我想在返回数据源后在我的kendo-ui下拉列表中设置索引。我能够使用复选框(不想使用),我可以在数据源为本地json的下拉列表中执行此操作。最后一个选项(我想要的那个)是根据从传输返回的数据源设置所选值。
那么,为什么这不起作用?
$("#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个选项的jsFiddle - http://jsfiddle.net/bensjones/H47b3/
有什么建议吗?
答案 0 :(得分:4)
您应该等到请求完成后 - a.k.a。使用 dataBound 事件并执行初始绑定,您应该将AutoBind选项设置为true。
$("#products-dropDownList-remote").data('kendoDropDownList').one("dataBound", function() { this.select(1) });;
此处已更新Fiddle。