0
我已經創建了下面的代碼FilteringSelect來:如何在Dojo 1.7中重新加載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();