kendo-ui - 添加新记录后,Kendo Grid调用 'create'操作而不是 'update'

标签 kendo-ui kendo-grid

我已经设置了基本的Kendo Grid,并且正在使用服务器端PHP Wrapper库中的DataSourceResult类。

我遇到了一个奇怪的问题……如果我对新记录进行create然后编辑(不刷新页面),则再次调用create操作,而不是update操作。

如果在添加新记录后刷新页面,则对记录进行更改后将正确调用update操作。

我可以确认create操作后,DataSourceResult类正在返回正确的数据,包括新记录的id

任何想法为什么会发生这种情况(以及如何阻止它)?
谢谢

更新:这是数据源代码。网址中的查询字符串只是为了轻松区分Chrome控制台中的请求。 ajax.php使用与每个请求一起传递的其他数据来区分请求的不同操作。

data = new kendo.data.DataSource({
    transport: {
        create:  {
            url: '/ajax.php?r=gridCreate',
            dataType: 'json',
            type: 'post',
            data: { request: 'grid', type: 'create' }
        },
        read:  {
            url: '/ajax.php?request=gridRead',
            dataType: 'json',
            type: 'post',
            data: { request: 'grid', type: 'read' }
        },
        update: {
            url: '/ajax.php?r=gridUpdate',
            dataType: 'json',
            type: 'post',
            data: { request: 'grid', type: 'update' }
        },
        destroy: {
            url: '/ajax.php?r=gridDestroy',
            dataType: 'json',
            type: 'post',
            data: { request: 'grid', type: 'destroy' }
        },
        parameterMap: function(data, operation) {
            if (operation != "read"){
              data.expires = moment(data.expires).format('YYYY-MM-DD HH:mm');
            }
            return data;
        }
    },
    schema: {
        data: 'data',
        total: 'total',
        model: {
            id: 'id',
            fields: {
                id: { editable: false, nullable: true },
                code: { type: 'string' },
                expires: { type: 'date' },
                enabled: { type: 'boolean', defaultValue: true }
            }
        }
    },
    pageSize: 30,
    serverPaging: true,
    serverSorting: true,
    serverFiltering: true 
});

最佳答案

我也有同样的问题,我已经尝试过了,并且可以正常工作。

.Events(events => events.RequestEnd("onRequestEnd"))

并在此功能中使用以下:
function onRequestEnd(e) {
    var tmp = e.type;
    if (tmp == "create") {
        //RequestEnd event handler code
          alert("Created succesully");
        var dataSource = this;
        dataSource.read();
    }
    else if (tmp == "update") {
          alert("Updated succesully");
    }
}

尝试在网格的onRequestEnd事件中使用此代码
var dataSource = this;
    dataSource.read();

希望对您有帮助。

关于kendo-ui - 添加新记录后,Kendo Grid调用 'create'操作而不是 'update',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20380473/

相关文章:

node.js - 如何使用命令行安装kendo grid

javascript - 自定义复选框在剑道网格中不可单击

jquery - 使用外部 css 文件时优先/忽略 CSS 规则(kendo ui 和 bootstrap)

javascript - Kendo GRID - 单击 "Add new row"按钮后获取 kendo grid Uncaught TypeError : Cannot read property of 'name' null

弹出式剑道网格的 Css 在 chrome 上损坏

javascript - 复选框事件未使用 jquery 触发

jquery - Kendogrid 过滤器菜单在 mouseleave 上关闭

javascript - 为 Kendo 网格中的某些行设置 Editable False

kendo-ui - 上下拖动元素时自动滚动Kendo TreeView

json - 使用 Kendo-ui Grid 进行 react - 错误的列标题