Ben*_*nes 0 javascript ajax kendo-ui
返回数据源后,我试图在我的 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);
Run Code Online (Sandbox Code Playgroud)
这是一个包含所有 3 个选项的 jsFiddle - http://jsfiddle.net/bensjones/H47b3/
有什么建议?
您应该等到请求完成 - 也就是使用dataBound事件并执行初始绑定,您应该将 AutoBind 选项设置为 true。
$("#products-dropDownList-remote").data('kendoDropDownList').one("dataBound", function() { this.select(1) });;
Run Code Online (Sandbox Code Playgroud)
这是更新的Fiddle。
| 归档时间: |
|
| 查看次数: |
3727 次 |
| 最近记录: |