jquery - 删除命令不触发数据源的销毁传输方法

标签 jquery kendo-ui kendo-grid datasource

我在 Kendo 网格的一列中定义了一个销毁命令:

columns: [
    {
        field: "Address",
        width: "200px"
    },
    {
        field: "City"
    },
    {
        field: "State",
        width: "40px"
    },
    {
        field: "Zip",
        width: "60px"
    },
    {
        field: "Active",
        width: "50px"
    },
    {
        command: ["edit", "destroy"],
        title: " ",
        width: "210px" 
    }
]

网格的“可编辑”设置为内联。数据源的 Batch 设置为 true。

编辑和保存工作正常(所有模型都以 JSON 格式发送到 SAVE 方法)。

但是当我单击其中一行的“删除”时,它会从网格中删除该行,但它的行为就像我保存所有项目一样。它调用 save 方法并以 JSON 对象发送每一行(除了我想要删除的行)。

问题是:为什么不调用 destroy 方法?

它不应该调用 destroy 方法并仅发送要删除的行吗?

数据源定义:

dataSource: {
    error    : function (e) {
        CustomError(e);
    },
    type     : "json",
    transport: {
        read        : {
            contentType: "application/json; charset=utf-8",
            type       : "POST",
            url        : "../Services/svcPerson_Address.asmx/Search",
            dataType   : "json",
            cache      : false,
            complete   : function (e) {
                //alert(e);
            }
        },
        update      : {
            contentType: "application/json; charset=utf-8",
            type       : "POST",
            url        : "../Services/svcPerson_Address.asmx/Save",
            dataType   : "json",
            cache      : false,
            complete   : function (e) {
                if (typeof (e.responseText) != "undefined") {
                    var response = $.parseJSON(e.responseText);
                }
            }
        },
        destroy     : {
            contentType: "application/json; charset=utf-8",
            url        : "../Services/svcPerson_Address.asmx/Delete",
            type       : "POST",
            dataType   : "json",
            cache      : false,
            complete   : function (e) {
            }
        },
        create      : {
            contentType: "application/json; charset=utf-8",
            type       : "POST",
            url        : "../Services/svcPerson_Address.asmx/Save",
            cache      : false,
            complete   : function (e) {
                if (typeof (e.responseText) != "undefined") {
                    var response = $.parseJSON(e.responseText);
                }
            }
        },
        parameterMap: function (options, operation) {
            if (operation !== "read" && options.models) {
                return kendo.stringify({ models: options.models });
            }

            options.PersonId = 0;
            if (viewModel.SelectedPreceptor != null) {
                if (viewModel.SelectedPreceptor.PersonId != "" && viewModel.SelectedPreceptor.PersonId != null) {
                    options.PersonId = viewModel.SelectedPreceptor.PersonId;
                }
            }

            return kendo.stringify(options);
        }
    },

最佳答案

我也遇到了同样的问题: 模型中设置了错误的 id。

我的代码是:

model: {
    id: "Id",
    fields: {
        UserId: { editable: false },
        ....

但应该是:

model: {
    id: "UserId",
    fields: {
        UserId: { editable: false },
        ....

关于jquery - 删除命令不触发数据源的销毁传输方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15122709/

相关文章:

Javascript 给出未定义的错误,尽管看起来一切正常

javascript - Kendo UI 和 Angularjs : make grid inline editable

jquery - 从 json 对象获取键名

jquery - 从特定标签中删除样式属性

javascript - 在热图 highcharts jquery 中添加额外信息,例如数据属性或 id

grid - 剑道 UI 网格卡住列

javascript - Kendo 网格拖放不适用于较少数量的记录

javascript - 类别轴交互

c# - Kendo MVC 在 Update 调用上触发 Create 方法

kendo-ui - Kendo UI Angular 过滤器菜单在 kendo timepicker 中选择时间时自动关闭