直觉上,人们会select.set("store", store)
像所有小部件一样将存储分配/更改为 dijit dojo/Stateful
,但令人惊讶的是它不起作用。
无论如何,有一种方法select.setStore(store, selectedValue, fetchArgs)
(也令人惊讶)未被弃用并且有效。
定义dijit/form/Select
没有商店:
<select id="select1" data-dojo-type="dijit/form/Select"></select>
为其分配一个商店:
require([
"dojo/ready",
"dijit/registry",
"dojo/store/Memory",
], function(
ready, registry, Memory
) {
ready(function() {
var store1 = new Memory({
idProperty: "value",
data: [
{ value: "AL", label: "Alabama" },
{ value: "AK", label: "Alaska" },
{ value: "AZ", label: "Arizona" }
]
});
var select1 = registry.byId("select1");
select1.set("labelAttr", "label");
select1.setStore(store1, "AZ");
});
});
在 jsFiddle 上查看它的实际效果:http: //jsfiddle.net/phusick/ZmsY V/
将一些UX糖添加到上述我将dijit/form/Select
disabled
使用单个选项创建,例如Loading...及其最终期望width
:
<select
id="select1"
data-dojo-type="dijit/form/Select"
data-dojo-props="disabled:true"
style="width:150px;"
>
<option>Loading...</option>
</select>
然后我会在调用后启用它setStore()
:
var select1 = registry.byId("select1");
select1.set("labelAttr", "label");
select1.setStore(store1);
select1.set("disabled", false);
在工作中查看此增强版:http: //jsfiddle.net/phusick/xdDEm/