我使用以下代码创建了FilteringSelect:
var type = $('fMatlTypeId').value;
var eSelect, dataStore;
require([
"dijit/form/FilteringSelect",
"dojo/store/Memory",
"dojo/data/ObjectStore",
"dojo/_base/xhr",
"dojo/parser",
"dojo/domReady!"
], function(FilteringSelect, Memory, ObjectStore, xhr){
xhr.get({
url: 'adminservices/admin/materialType/assignedFacilities/' + type + '/',
handleAs: "json"
}).then(function(data){
dataStore = new ObjectStore({ objectStore:new Memory({ data: data.items }) });
eSelect = new FilteringSelect({
id: 'fMatlTypeFacilities',
store: dataStore,
searchAttr: 'nameStatus',
queryExpr: '*${0}*',
ignoreCase: true,
autoComplete: false,
style: 'width:200px',
required: true
}, document.createElement('div'));
// Append to the div
$('FS_MatlTypeFacilities').innerHTML = '';
dojo.byId("FS_MatlTypeFacilities").appendChild(eSelect.domNode);
eSelect.startup();
eSelect.setValue(dataStore.objectStore.data[0].id);
});
});
现在,如果后端数据发生变化,我该如何重新加载?
我尝试了以下代码,当我在Firebug中调试它时,商店会更新,但不会更新FilteringSelect。
var eSelect, dataStore;
require([
"dijit/form/FilteringSelect",
"dojo/store/Memory",
"dojo/data/ObjectStore",
"dojo/_base/xhr",
"dojo/parser",
"dojo/domReady!"
], function(FilteringSelect, Memory, ObjectStore, xhr){
xhr.get({
url: 'adminservices/admin/materialType/assignedFacilities/' + type + '/',
handleAs: "json"
}).then(function(data){
dataStore = new ObjectStore({ objectStore:new Memory({ data: data.items }) });
dataStore.fetch();
eSelect = dijit.byId('fMatlTypeFacilities');
eSelect.store.close();
eSelect.store = dataStore;
eSelect.startup();
});
});
有什么建议吗?
我发现的唯一工作就是每次都破坏小部件并让它重建。所以我在上面的创建代码之前添加了以下代码。但必须有一种方法可以简单地重新加载它。
if (dijit.byId('fMatlTypeFacilities')) dijit.byId('fMatlTypeFacilities').destroy();
答案 0 :(得分:3)
尝试更改:
eSelect.store = dataStore;
到
eSelect.set('store', dataStore);
通常,您应该通过myDijit.set('');访问dijit的属性。有关详细信息,请参阅here