不确定我在做什么错,但是我已经跟着apparoch解释了。我想,我也将对象添加到商店对象中。但同样没有在UI上反映出来。下拉仍然是空白。可以sombody请帮助。
我的选择框代码:
<div class="ecmSearchFormInputArea">
<table class="ecmSearchFormInputArea">
<tr>
<td class="propertyRowLabel">
<label><span class="mandatory_red"></span>Cost Center :</label>
<select data-dojo-attach-point="costCenter" id="costCenter"
data-dojo-type="dijit/form/FilteringSelect" style="width: 18em;"
data-dojo-attach-event="onChange:loadDocStacks">
</select>
</td>
</tr>
</table>
</div>
我的JS
postCreate: function() {
this.logEntry("postCreate");
//Trying to populate Combobox
var storeData = {
identifier: 'costCenter',
items: []
}
var jsonObj = [{
costCenter: 'sc1'
},
{
costCenter: 'sc2'
}]
dojo.addOnLoad(function () {
var costCenterStore = new dojo.data.ItemFileWriteStore({ data: storeData });
for (var i = 0; i < jsonObj.length; i++) {
alert ("value of i = " + jsonObj[i].costCenter);
costCenterStore.newItem(jsonObj[i]);
}
var serviceFilterSelect = dijit.byId('costCenter');
alert ("serviceFilterSelect " + serviceFilterSelect);
alert ("costCenterStore " + costCenterStore);
serviceFilterSelect.attr('store', costCenterStore);
});
//Trying to populate Combobox
this.logExit("postCreate");
},
FOR循环中的警报显示正确的数据。我错过了什么吗?
答案 0 :(得分:1)
添加标签属性和标识符。因为这将用作填充标签。
var jsonObj = [{
costCenter: 'sc1', name: 'label1'
},
{
costCenter: 'sc2', name: 'label2'
}];
var storeData = {
identifier: 'costCenter', label: 'name',
items: []
};