我已经使用以下代码创建了一个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中调试它时,商店得到了更新,但过滤选择没有更新。
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();
1条答案
按热度按时间vojdkbi01#
尝试更改:
到
一般来说,应该通过myDijit.set('')访问dijit的属性;。有关详细信息,请参阅here