Javascript 在ajax之后设置kendo ui dropdownlist控件的索引
在返回数据源后,我试图在我的kendo ui dropdownlist上设置索引。我可以通过一个复选框(不想使用)来完成它,并且可以在数据源为本地json的dropdownlist上完成。最后一个选项(我想要的)是基于从传输返回的数据源设置所选值 那么,为什么这不起作用呢Javascript 在ajax之后设置kendo ui dropdownlist控件的索引,javascript,ajax,kendo-ui,Javascript,Ajax,Kendo Ui,在返回数据源后,我试图在我的kendo ui dropdownlist上设置索引。我可以通过一个复选框(不想使用)来完成它,并且可以在数据源为本地json的dropdownlist上完成。最后一个选项(我想要的)是基于从传输返回的数据源设置所选值 那么,为什么这不起作用呢 $("#products-dropDownList-remote").kendoDropDownList({ dataTextField: "ProductName", dataValu
$("#products-dropDownList-remote").kendoDropDownList({
dataTextField: "ProductName",
dataValueField: "ProductID",
autoBind: false,
dataSource: {
transport: {
read: {
dataType: "jsonp",
url: "http://demos.telerik.com/kendo-ui/service/Products"
}
},
requestEnd: function (e) {
//is this how I set this after the request is successful? why doesn't it set it here?
$("#products-dropDownList-remote").data('kendoDropDownList').select(1);
}
}
});
//this doesn't feel like it should work, but does according
//to this forum thread
//http://www.telerik.com/forums/how-do-you-set-the-value-of-a-dropdownlist-after-reading-external-data
//it should....but it doesn't.
$("#products-dropDownList-remote").data('kendoDropDownList').select(1);
这是一个包含所有3个选项的JSFIDLE-
有什么建议吗?您应该等到请求完成-也称为。使用数据绑定事件,并且要执行初始绑定,您应该将自动绑定选项设置为true
$("#products-dropDownList-remote").data('kendoDropDownList').one("dataBound", function() { this.select(1) });;
此处已更新。您应该等待请求完成-也称为。使用数据绑定事件,并且要执行初始绑定,您应该将自动绑定选项设置为true
$("#products-dropDownList-remote").data('kendoDropDownList').one("dataBound", function() { this.select(1) });;
这里有更新