我正在使用像这样的几个自定义编辑器
function checkListEditor(container, options) {
$('<input required data-text-field="Name" data-value-field="Id" data-bind="value:CheckListId"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataTextField: "Name",
dataValueField: "Id",
dataSource: {
transport: {
read: '@Url.Action("GetCheckLists", "CheckList")',
dataType: "json"
}
},
change: function (e) {
var dataItem = this.dataItem(e.item);
options.model.set("CheckListName", dataItem.Name);
}
});
}
我正在从db获取dataSource。更新工作没有问题,但创建却没有。预先选择的值有误。当我离开它时,它变成空的。如何解决?所有编辑器中都存在该问题。当我从下拉列表中选择其他值时,所有工作都会如预期
<script>
$(document).ready(function () {
$("#checklist-grid").kendoGrid({
dataSource: {
type: "json",
transport: {
read: {
url: "@Html.Raw(Url.Action("List", "CheckListStep"))",
type: "POST",
dataType: "json",
data: additionalData
},
create: {
url: "@Html.Raw(Url.Action("Create", "CheckListStep"))",
type:"POST",
dataType: "json",
data: additionalData
},
update: {
url: "@Html.Raw(Url.Action("Edit", "CheckListStep"))",
type:"POST",
dataType: "json",
data: additionalData
},
parameterMap: function (options, operation) {
if (operation !== "read" && options.models) {
return { models: kendo.stringify(options.models) };
} else {
addAntiForgeryToken(options);
return options;
}
}
},
schema: {
data: "Data",
total: "Total",
errors: "Errors",
model: {
id: "Id",
fields: {
Id:{editable:false},
AssignedToId:{editable:true,type:"number"},
AssignedToName:{type:"string"},
DefaultOwnerId:{editable:true,type:"number"},
DefaultOwnerName:{type:"string"},
CheckListId:{editable:true,type:"number",validation:{required:true}},
CheckListName:{type:"string"},
}
}
},
requestEnd: function (e) {
if (e.type == "read") {
var response = e.response;
if (response) {
//store extra data
reportAggregates = e.response["ExtraData"];
}
}
if (e.type == "update" || e.type == "create") {
this.read();
}
},
},
pageable: {
refresh: true,
pageSizes: [@(gridPageSizes)]
},
editable: "incell",
toolbar: ["create","save","cancel"],
scrollable: false,
batch:true,
dataBound: onDataBound,
columns: [
{
field: "CheckListId",
title: "Check List",
width: 100,
editor: checkListEditor,
template: "#:CheckListName#"
},
{
field: "DefaultOwnerId",
title: "Default owner",
width: 100,
editor: ownerEditor,
template: "#:DefaultOwnerName#"
},
{
field: "AssignedToId",
title: "Assigned To",
width: 100,
editor: assignedEditor,
template: "#:AssignedToName#"
},
{ command: ["destroy"], title: " ", width: "250px" }
]
});
});
</script>