Programmatically set the selected value of a dijit Select widget

*爱你&永不变心* 提交于 2019-12-05 04:21:53
selectWidget.set("value", someValue);

If you are specifying options via the options property (array of objects with label, value, etc.), then someValue should match the value of one of those objects. (Note that you can also specify selected: true right within one of the objects in the array passed to options.)

If you are providing items from a dojo.data store via the store property, then someValue should match the identity of one of the store's items.

(edit) NOTE: I assumed above that by "dijit select widget" you are referring to dijit.form.Select. If you are actually using dijit.form.ComboBox or dijit.form.FilteringSelect, the same line of code still holds true, as applicable to stores in the last paragraph. In the case of declarative instantiation with a select tag, ComboBox and FilteringSelect still create a store, whose items' identities are the values of the options within the select tag.

//With dojo version 1.9
//search for the item in store dojo/store/Memory with the corresponding id value
var objItem = store.get("1");
//set the combobox's item
comboBox.set("item", objItem);
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!