有人可以提供一個例子,說明如何將以下兩個屬性綁定到我的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);
}
});