Nan*_*ner 4 jquery datasource kendo-ui kendo-grid
我在 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"
}
]
Run Code Online (Sandbox Code Playgroud)
Editable 设置为内联网格。数据源的 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);
}
},
Run Code Online (Sandbox Code Playgroud)
小智 5
我遇到了同样的问题:模型中设置了错误的 id。
我的代码是:
model: {
id: "Id",
fields: {
UserId: { editable: false },
....
Run Code Online (Sandbox Code Playgroud)
但应该是:
model: {
id: "UserId",
fields: {
UserId: { editable: false },
....
Run Code Online (Sandbox Code Playgroud)