如何从 dijit/form/select 中删除所有选项?

how to remove all options from a dijit/form/select?

我在我的网页上使用了一个非常简单的 dijit/form/select 我通过这样的代码添加了几个选项:

option1 = { value: "o1", label: "option 1", selected: false };
option2 = { value: "o2", label: "option 2", selected: true };

this.mySelect.addOption([option1, option2]);   

它正在工作。 但是,当我尝试使用此代码清除 dijit/form/select 时:

this.mySelect.removeOption(this.mySelect.getOption());

我的所有选项都没有了,除了选中的那个。

我尝试使用 .reset 甚至 .value = '' 但没有任何效果。

那么如何从 dijit/form/select 中删除所有选项?

其实答案很简单,但没有很好的记录(it's pretty hard to find, like all dojo related stuff)

this.mySelect.removeOption(lang.clone(option1));
this.mySelect.removeOption(lang.clone(option2));

this.mySelect.store = null;
this.mySelect.set('value', '');
this.mySelect._setDisplay(""); //This line alone should do the trick

As in the comments, the last line should do the trick, but this way you can be sure that the select element gets cleared.

演示: JSFiddle demo