最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Kendo ui dropdownlist remove specific item - Stack Overflow

programmeradmin1浏览0评论

I have a dropdownlist that I fill from a datasource. After a specific event, I want to remove one item from my dropdownlist with id = 22. (I know it's weird and hardcoding but not much time for a newbie left). Is that possible? How can I do that?

I have a dropdownlist that I fill from a datasource. After a specific event, I want to remove one item from my dropdownlist with id = 22. (I know it's weird and hardcoding but not much time for a newbie left). Is that possible? How can I do that?

Share Improve this question edited Aug 5, 2014 at 14:01 TLS 3,1502 gold badges27 silver badges33 bronze badges asked May 8, 2014 at 19:31 rean24rean24 631 silver badge7 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

This is a quick and dirty way to acplish the task using the Kendo DataSource remove method. It assumes your drop down is bound to an object containing a property called "id". If you're using the standard text/value key value pair object, then replace the if statement with if (item.Value == 22).

var dropdown = $('#dropDownId').data("kendoDropDownList");

var raw = dropdown.dataSource.data();
var length = raw.length;

var item, i;
for(i=length-1; i>=0; i--){

  item = raw[i];
  if (item.id == 22) {
    dataSource.remove(item);
    break;
  }

}

Source: http://blogs.telerik./kendoui/posts/13-01-29/adding_and_removing_items_in_kendo_data_datasource

You can access the parent of this item and then remove it as a child of parent:

  document.getElementById("22").parentNode.removeChild(document.getElementById("22"));

getElementById("22") gets an element which has id "22"

parentNode is parent of an element. In your case, it is dropdown

removeChild(document.getElementById("22")) removes the specified child from its patent. In your case, an element which has id "22".

发布评论

评论列表(0)

  1. 暂无评论