我试图在AJAX的数据来之后选择DropDownList值,但我的解决方案不起作用 这是我的代码:
function openWindow(e) {
var wdw = $("#myWindow").data("kendoWindow");
wdw.open();
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var grid = $("#grid").data("kendoGrid");
grid.dataSource.transport.options.read.url = '@Url.Action("BindingList", "AttributeBinding")' + "?formId=" + dataItem.FormId;
grid.dataSource.read();
$("#title").html(dataItem.FormTitle);
$("#dropdown").kendoDropDownList({
optionLabel: "- please select -",
dataTextField: "StringValue",
dataValueField: "Id",
dataSource: {
transport: {
read: {
url: '@Url.Action("PopUpBind", "AttributeBinding")',
dataType: "json",
},
},
requestEnd: function () {
$("#dropdown").data('kendoDropDownList').value(dataItem.MultiLinkerProductAttributeId);
}
}
});
};
当加载DropDown时,我可以通过Web浏览器控制台设置#dropdown值,但是这个相同的代码不能与dataSource中的requestEnd函数一起使用
答案 0 :(得分:3)
完成数据请求但时,requestEnd中的事件DataSource会被触发,但不必将数据绑定到窗口小部件。由于选择涉及窗口小部件(DropDownList),因此您应使用dataBound
您的代码类似于:
function openWindow(e) {
var wdw = $("#myWindow").data("kendoWindow");
wdw.open();
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
var grid = $("#grid").data("kendoGrid");
grid.dataSource.transport.options.read.url = '@Url.Action("BindingList", "AttributeBinding")' + "?formId=" + dataItem.FormId;
grid.dataSource.read();
$("#title").html(dataItem.FormTitle);
$("#dropdown").kendoDropDownList({
optionLabel: "- please select -",
dataTextField: "StringValue",
dataValueField: "Id",
dataSource: {
transport: {
read: {
url: '@Url.Action("PopUpBind", "AttributeBinding")',
dataType: "json",
},
}
},
databound: function(e) {
this.value(dataItem.MultiLinkerProductAttributeId);
}
});
};