javascript 如何修改 KendoUI DropDownList 项
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10336989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to modify KendoUI DropDownList items
提问by dasheddot
We used the Kendo UI DropDownList the first time without binding with knockout. Via jquery a usual html input is transformed into a KendoUI DropDownList. But how can i remove/edit/add items to the options?
我们第一次使用 Kendo UI DropDownList,没有绑定淘汰赛。通过 jquery,通常的 html 输入被转换为 KendoUI DropDownList。但是我如何删除/编辑/添加项目到选项?
If i modify the html inputs options via jquery it has no influence on the kendoui dropdown - even with a refresh call afterwards.
如果我通过 jquery 修改 html 输入选项,它对 kendoui 下拉列表没有影响 - 即使之后进行刷新调用。
Any ideas how to do this? Thanks
任何想法如何做到这一点?谢谢
回答by Petur Subev
Yo mate
哟伙计
You should use the dataSourceof the combobox. e.g.
您应该使用的数据源的组合框的。例如
var ds = $('#YourCombo').data().kendoComboBox.dataSource;
then you can modify the items like this
然后你可以像这样修改项目
//someIndex is the index of the item in the dataSource
ds.data()[someIndex].set("text","Cool! its changed");
to add item or remove use the addand removemethods of the dataSource
添加项目或删除使用数据源的添加和删除方法
ds.add({text:"Test again!",value:"5"});