我有一个这样的枚举
define({
DEFAULT:1,
DDL:2,
props:{
1:{name: 'Default', value:1, id:1},
2:{name: 'DDL', value:2, id:2}
}
});
,我想将其加载到dijit/form/FilteringSelect
这是我的代码
var store = new Memory({
idProperty: "id",
data: type.props
});
var os = new ObjectStore({objectStore: store});
this.unitType = new Select({
name : 'name',
label : dojoConfig.i18n.unitType,
placeHolder: dojoConfig.i18n.unitType,
required: false,
store: os,
value: type.props[1].id,
searchAttr: 'name',
labelAttr: "name",
trim: true
});
但是当我展开下拉列表时...它不会展开且在控制台中没有任何错误...知道我做错了什么吗?谢谢
答案 0 :(得分:1)
您的下拉列表未显示任何内容,因为给定的数据不是Array,而是js对象
dojo/store/Memory需要一个ana数组作为数据,
因此,要解决此问题,您可以通过将对象更改为数组来编辑对象,或者通过创建对象并将其设置为select,然后使用Object.values(yourObject)
将此对象从对象返回值数组进行编辑。
请参见下面的工作片段:
require(["dijit/registry", "dijit/form/FilteringSelect", "dojo/store/Memory", "dojo/data/ObjectStore"],
function(registry, FilteringSelect, Memory, ObjectStore) {
var type = {
DEFAULT: 1,
DDL: 2,
props:{
1:{name: 'Default', value:1, id:1},
2:{name: 'DDL', value:2, id:2}
}
};
type.props = Object.values(type.props);
var store = new Memory({
idProperty: "id",
data: type.props
});
var os = new ObjectStore({
objectStore: store
});
new FilteringSelect({
name: 'name',
required: false,
store: os,
value: type.props[1].id,
searchAttr: 'name',
labelAttr: "name",
trim: true
}, "select");
});
<script>
dojoConfig = {
isDebug: true,
parseOnLoad: true,
};
</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<link href="//ajax.googleapis.com/ajax/libs/dojo/1.10.0/dijit/themes/claro/claro.css" rel="stylesheet" />
<body class="claro">
<select id="select">
</select>
</body>