所以在我看来我有这个
<div id="grid"></div>
<script>
$(document).ready(function () {
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: '@Url.Action("GetCityList", "City")',
dataType: "json",
type: "GET",
contentType: "application/json; charset=utf-8"
},
create: {
url: '@Url.Action("create", "City")',
type: "Post"
},
parameterMap: function (data, operation) {
if (operation != "read") {
var result = {};
for (var i = 0; i < data.models.length; i++) {
var ciudad = data.models[i];
for (var member in ciudad) {
result["ciudades[" + i + "]." + member] = ciudad[member];
}
}
return result;
}
}
},
batch: true,
pageSize: 30,
schema: {
model: {
id: "id",
fields: {
id: { editable: false, nullable: true },
descripcion: { validation: { required: true} },
DepartamentName: { field: "DepartamentName" },
}
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
pageable: true,
height: 400,
toolbar: ["create", "save", "cancel"],
columns: [
"descripcion",
{ field: "DepartamentName", title: "Name Departament", editor: categoryDropDownEditor, width: 150 },
{ command: "destroy", title: " ", width: 110}],
editable: true
});
});
</script>
<script>
function categoryDropDownEditor(container, options) {
$('<input data-text-field="name" data-value-field="name" data-bind="value:' + options.field + '"/>')
.appendTo(container)
.kendoDropDownList({
autoBind: false,
dataSource: {
type: "json",
transport: {
read: {
url: '@Url.Action("GetDepartament", "city")
}
}
}
});
}
</script>
它告诉我没问题,但我的问题是,当它击中我的操作时,它会给我部门的名称而不是 id
当我改变我的功能这部分到这个
$('<input data-text-field="name" data-value-field="name" data-bind="value:' + options.field + '"/>')
$('<input data-text-field="name" data-value-field="id" data-bind="value:' + options.field + '"/>')
有了它,我的动作很好,我得到了 id,但是在我的网格中,当我在下拉列表中选择网格中的一个部门时,它显示了我的 id(所以不是我想要的行为)
我该怎么做才能让它发挥作用?我猜它在绑定部分..