我已根据odata服务创建了一个剑道网格,如下面的代码所示。这会在列表中显示值,但是当新记录不起作用时。这是因为它不仅发送创建的值,而且还发送列表的文本。
@model IEnumerable<SE.CloudMonitor.Web.Models.ObjectType>
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/CloudMonitor.cshtml";
}
<h2 class="tituloVista">Objetos</h2>
<div id="grid"></div>
<script>
$(document).ready(function () {
kendo.culture("es-CO");
var ObjectType = [
@foreach (var item in Model)
{
@: { "value": @Html.DisplayFor(modelItem => item.ObjectTypeID) ,'text':" @Html.DisplayFor(modelItem => item.ObjectTypeName) "},
}
];
var crudServiceBaseUrl = "Services/CloudMonitor.svc/Objects",
dataSource = new kendo.data.DataSource({
type: "odata",
transport: {
read: {
url: crudServiceBaseUrl,
dataType: "json"
},
update: {
url: function (data) {
return crudServiceBaseUrl + "(" + data.ObjectsID + ")";
}
},
create: {
url: crudServiceBaseUrl
},
destroy: {
url: function (data) {
return crudServiceBaseUrl + "(" + data.ObjectsID + ")";
}
}
},
batch: false,
pageSize: 5,
serverPaging: true,
schema: {
model: {
id: "ObjectsID",
fields: {
ObjectsID: { editable: false, nullable: true },
ObjectTypeID: { editable: true, nullable: true },
ObjectName: { editable: true, nullable: true }
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
pageable: true,
height: 400,
toolbar: ["create"],
columns: [
{ field: "ObjectName", width: "150px", title:"Nombre objeto" },
{ field: "ObjectTypeID", width: "150px", values: ObjectType, title: "Tipo objeto" },
{ command: ["edit", "destroy"], title: " ", width: "110px" }],
editable: "popup"
});
});
</script>
更新2014-02-19 在搜索了许多解决方案后,我发现kendo组合框不起作用。为了解决这个问题,我将模板和编辑器与select标签放在一起,现在工作正常。