有人可以提供一个例子,说明如何将以下两个属性绑定到我的BookType Kendo DropDown?我需要将dataTextField绑定到“Name”,并将dataValueField绑定到“BookTypeId”。KendoUI DropDownList如何绑定
的数据回来在下面的形式:
books: Object
bookTypes: Array[4]
0: Object
ID: 1
Name: "Web Development"
BookTypeId: 1
1: Object
ID: 2
Name: "Networking"
BookTypeId: 2
2: Object
ID: 3
Name: "Game Development"
BookTypeId: 3
3: Object
ID: 4
Name: "OS Development"
BookTypeId: 4
这是我做的电话:
$.ajax({
async: false,
type: "GET",
url: "GetBookTypes",
contentType: "application/json",
dataType: "json",
success: function (res) {
if (typeof res !== "undefined" && typeof res.Errors !== "undefined") {
if (res.Errors.length > 0) {
// Display each error
for (var i = 0; i < res.Errors.length; i++) {
alert(res.Errors[i].ErrorMessage);
}
}
} else if (typeof res !== "undefined") {
$("#BookType").kendoDropDownList({
dataTextField: "Name",
dataValueField: "BookTypeId",
dataSource: res,
}).data("kendoDropDownList");
}
},
complete: function() {
},
error: function (res) {
alert(res.responseText);
}
});