ASP.NET Web API에서 Kendo UI를 사용하고 있습니다. 필요한 모든 메소드를 가진 ProjectsController가 있습니다.Kendo UI DataSource가 transport.destroy를 트리거하지 않음
내 문제는 내가 Delete
버튼을 클릭하면, 검도 UI 그리드 remove()
이벤트를 발생시킬 것입니다,하지만 DataSource
결코 transport.destroy
를 호출하지 않습니다. 오히려 tansport.create
이 호출 된 것 같습니다. transport.parameterMap
에서 이 대신이 아니라을 생성한다는 것을 알 수 있습니다. 요청이 피들러를 통해 발행 될 때
$(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();
}
});
});
웹 API는 잘 작동하지만 검도 UI 그리드 보여줍니다 : 여기
은 샘플 자바 스크립트 코드POST http://localhost:port/api/Projects
이 DELETE
을해야 할 때.
미리 감사드립니다.
사실 실제로 그렇지 않습니다. 나는 (sync()를 호출하는지 또는'autoSync'가 true로 설정되었는지에 관계없이 웹 API에 대한 호출이 이루어지고 있음을 볼 수있다. 나는 batch를 false로 설정하려고 시도했으나 transport.create 문제는 삭제가'transport.destroy'를 발생시키지 않는다는 것인데, 아이템을 지울 때'transport.create'를 계속 올리는 것입니다. –
코드에 아무 것도 보이지 않습니다.이 포스트를 보시오 OnaBai 's answer 당신이 정의하지 않은 것 같은 당신의 모델에서 ID의 요구 사항을 설명합니다 : http://stackoverflow.com/questions/16662223/why-does-the-kendoui-grid-transport-create-event-gets-raised-multiple-times - – Vojtiik
고마워! 모델 내부에 ID를 추가하는 것은 해결책이다. –