[英]Removing Items from Telerik Drop down list using jQuery
I know how to add items to a telerik ddl using jquery, but how do I remove values?我知道如何使用 jquery 向 Telerik ddl 添加项目,但如何删除值?
Thanks in advance提前致谢
Here is a demo of RadComboBox with Add/Remove/Disable Items ...这是带有添加/删除/禁用项目的 RadComboBox 的演示......
http://demos.telerik.com/aspnet-ajax/combobox/examples/programming/addremovedisableitemsclientside/defaultcs.aspx http://demos.telerik.com/aspnet-ajax/combobox/examples/programming/addremovedisableitemsclientside/defaultcs.aspx
Basically - you need to first get combo box itself.基本上 - 您需要首先获得组合框本身。 Here is the code:这是代码:
var combo = $find("<%= RadComboBox1.ClientID %>");
Lets assume you want to remove the currently selected item in the combo box.假设您要删除组合框中当前选定的项目。 You will need to first grab the item like below:您需要先获取如下项目:
var comboItem = combo.get_selectedItem();
Now to remove the above item from the combo box, we first need to get the items collection and then call the remove method on the collection by passing the item we want to remove.现在要从组合框中删除上述项目,我们首先需要获取项目集合,然后通过传递我们要删除的项目来调用集合上的 remove 方法。 Here is the code snippet for the same:这是相同的代码片段:
if(comboItem)
{
combo.trackChanges();
combo.get_items().remove(comboItem);
combo.commitChanges();
}
Here is another example of removing an item from the combobox - this time we search the item by its name:这是从组合框中删除项目的另一个示例 - 这次我们按名称搜索项目:
var combo = $find("<%= RadComboBox1.ClientID %>");
var items = combo.get_items();
var comboItem = combo.findItemByText("Paris");
combo.trackChanges();
items.remove(comboItem);
combo.commitChanges();
Here is the documentation for the client side API of ComboBox (disclaimer: I'm part of Telerik):这是 ComboBox 客户端 API 的文档(免责声明:我是 Telerik 的一部分):
http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcomboboxitemcollection.html http://www.telerik.com/help/aspnet-ajax/combobox-client-side-radcomboboxitemcollection.html
this will remove all items from dropdown .这将从下拉列表中删除所有项目。
var combo2 = $find('<%= drp_Year.ClientID%>'); var combo2 = $find('<%= drp_Year.ClientID%>');
combo2.get_items().clear() combo2.get_items().clear()
https://a2zcode.com/Removing-Items-from-Telerik-Drop-down-list-using-jQuery https://a2zcode.com/Removing-Items-from-Telerik-Drop-down-list-using-jQuery
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.