开发者

Remove Telerik MVC DropList Item via Jquery

开发者 https://www.devze.com 2023-04-11 00:14 出处:网络
I am trying to remove an item fr开发者_StackOverflow中文版om my telerik MVC dropList with Jquery.It seems that the conventional approach does not work...

I am trying to remove an item fr开发者_StackOverflow中文版om my telerik MVC dropList with Jquery. It seems that the conventional approach does not work...

$("#Type option[value='02']").remove();

Is there any way to remove an item from this dropList control?

Thank you


apprently, telerik uses lists and a bunch of css to create "virtual" selects.

$("#Type li:contains('02')").remove();

http://jsfiddle.net/roselan/mvyU6/2/


As you probably know, there is no consistent way to richly style and customize HTML <select> elements. That is why the Telerik Combobox for MVC does not directly use this element.

Instead, the Combobox uses a rich client-side object, HTML, and CSS, and "binds" to data that defines your list of options. Rather than hacking at the Combobox HTML to visually remove an item, a better approach is to use the Combobox API.

You can use code like this to remove elements from the data array bound to the Combobox:

//Get the Telerik Combobox client-side object    
var comboBox = $("#ComboBox").data("tComboBox");
//Get the array of objects bound to the drop down list
var ds = comboBox.data;
//Rebind (and in turn, re-render) the drop down after modifying the source array
comboBox.dataBind(ds.splice(1,1));

Where in this example, only 1 item will be left in your Combobox dropdown.

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消