Kendo UI数据源未触发transport.destroy [英] Kendo UI DataSource not triggering transport.destroy
问题描述
我正在将Kendo UI与ASP.NET Web API一起使用.有一个包含所有必要方法的ProjectsController.
I am using Kendo UI with ASP.NET Web API. There is a ProjectsController that has all the necessary methods.
我的问题是,当我单击Delete
按钮时,Kendo UI网格将引发remove()
事件,但是DataSource
从不调用transport.destroy
.相反,似乎正在调用tansport.create
.在transport.parameterMap
中,我可以看到该操作是 create 而不是 destroy .
My issue is that when I click on Delete
button, Kendo UI grid will raise remove()
event, but DataSource
never invokes transport.destroy
. Rather, it seems that tansport.create
is being invoked. In transport.parameterMap
I can see that the operation is create instead of destroy.
以下是示例JavaScript代码:
Here is a sample JavaScript code:
$(document).ready(function () {
var apiUrl = '/api/projects/';
var dataType = 'json';
var dataSource = new kendo.data.DataSource({
batch: true,
autoSync: false,
transport: {
read: {
url: apiUrl,
dataType: dataType,
type: "GET"
},
update: {
url: apiUrl,
dataType: dataType,
type: "PUT"
},
destroy: {
url: apiUrl,
type: "DELETE"
},
create: {
url: apiUrl,
contentType: "application/json;charset=utf-8",
dataType: dataType,
type: "POST"
},
parameterMap: function (data, operation) {
console.log("Operation: " + operation);
if (operation === "create" && data.models) {
for (var i in data.models) {
var model = data.models[i];
if (model.ProjectId === 0) {
return kendo.stringify(model);
}
}
} else if (operation === "destroy") {
console.log("Data.Models: " + data.models);
console.log("Data.id: " + data.ProjectId);
return { id: data.ProjectId };
}
return data;
}
},
schema: {
id: "ProjectId",
model: {
fields: {
ProjectId: { type: "number", editable: false, nullable: false, defaultValue: 0 },
ProjectName: { type: "string", validation: { required: true } },
Status: { type: "string", validation: { required: true } },
IsActive: { type: "boolean" }
}
}
},
pageSize: 10,
serverPaging: false,
serverFiltering: false,
serverSorting: false
});
$("#projectsGrid").kendoGrid({
dataSource: dataSource,
groupable: false,
sortable: true,
pageable: {
refresh: true,
pageSizes: true
},
pageSize: 10,
toolbar: ["create"],
editable: "popup",
columns: [
{ field: "ProjectId", width: 30, title: "ID" },
{ field: "ProjectName", width: 180, title: "Project" },
{ field: "Status", width: 90, title: "Status" },
{ field: "IsActive", width: 40, title: "Is Active", type: "boolean", template: '<input type="checkbox" #if (IsActive) {# checked="checked" #}# disabled="disabled" />' },
{ command: ["edit", "destroy"], title: " ", width: "80px" }
],
remove: function (e) {
console.log("Delete button clicked.");
console.log("Project ID: " + e.model.ProjectId);
//dataSource.remove(e.model);
//dataSource.sync();
}
});
});
通过Fiddler发出请求时,Web API可以正常工作,但是Kendo UI Grid显示:
Web API works fine when requests are issued via Fiddler, but Kendo UI Grid shows:
POST http://localhost:port/api/Projects
应为DELETE
.
提前感谢大家!
推荐答案
在您的数据源上,您已将 batch 标志设置为true,这意味着数据源仅在告诉您后才进行呼叫例如,调用sync(). http://docs.kendoui.com/api/framework/datasource#configuration-批次
On your datasource, you have the batch flag set to true, this means the datasource will make the call only after you tell it to, e.g calling sync(). http://docs.kendoui.com/api/framework/datasource#configuration-batch
以及
Make sure you have defined Id in the model, as OnaBai explained here Why does the KendoUI Grid Transport Create event gets raised multiple times, and even when the action is Update? , your id is outside the model, should be in :
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
}
}
这篇关于Kendo UI数据源未触发transport.destroy的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!