删除命令不触发数据源的destroy传输方法

时间:2013-02-27 21:24:34

标签: jquery kendo-ui kendo-grid datasource

我在Kendo Grid的其中一列中定义了destroy命令:

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方法)。

但是当我点击其中一行的DELETE时,它会从网格中删除该行,但它的行为就像我保存所有项目一样。它调用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);
        }
    },

1 个答案:

答案 0 :(得分:4)

我有同样的问题: 在模型中设置了错误的ID。

我的代码是:

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

但应该是:

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