javascript 如果它是最后一项,如何删除剑道 dropDownList 的项目?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10382799/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 09:41:03  来源:igfitidea点击:

How to remove item of kendo dropDownList if it is the last one?

javascriptjqueryhtmlkendo-ui

提问by l.poellabauer

I can remove all items except the last one from the kendo dropdownlist. After the last one is removed, the previous items reappear.

我可以从剑道下拉列表中删除除最后一项之外的所有项目。删除最后一项后,之前的项会重新出现。

Here is a jsFiddle: http://jsfiddle.net/lpoellabauer/Jw4Cz/

这是一个 jsFiddle:http: //jsfiddle.net/lpoellabauer/Jw4Cz/

var dropDown = $("select").data("kendoDropDownList");
var itemToRemove = dropDown.dataSource.at(0);
dropDown.dataSource.remove(itemToRemove);
dropDown.select(0);

Any ideas how to solve this?

任何想法如何解决这个问题?

采纳答案by user1301411

HTML:

HTML:

<select>
<option value="1">one</option>
<option value="2">two</option>
<option value="3">three</option>
<option id="none" value="none"></option>
</select>

<a href="#">remove first</a>

JS:

JS:

$("select").kendoDropDownList();

$("a").click(function(){
    var dropDown = $("select").data("kendoDropDownList");
    var itemToRemove = dropDown.dataSource.at(0);
    dropDown.dataSource.remove(itemToRemove);
    dropDown.select(0);
});
$('none').css({display:none});

?

?