ExtJs Store有方法load和load方法有回調函數。
我創建了一個演示。你可以在這裏查詢Sencha fiddle
這個函數會創建存儲並返回。
function createStore(id) {
return Ext.create('Ext.data.Store', {
storeId: 'store_' + id,
alias: 'store.store_' + id,
proxy: {
type: 'ajax',
url: 'data.json',
timeout: 300000,
reader: {
type: 'json',
rootProperty: 'data'
}
}
});
}
例如,我有商店的陣列。它包含storeId或別名。
var storeArry = [],
store = '';
for (var key = 0; key < 5; key++) {
storeArry.push(createStore(key).storeId);
}
在每家商店的回調,我們可以從storeArray刪除數據或維持一個變量,用於檢查。
Ext.getBody().mask('Please wait..');
Ext.defer(function() {
Ext.getBody().unmask();
Ext.Array.forEach(storeArry, function (storeId) {
//For checking store is created or not
//if store is not created we can create dyanamically using passing storeId/alias
store = Ext.getStore(storeId);
if (Ext.isDefined(store) == false) {
store = Ext.create(storeId);
}
store.load({
callback: function() {
//On every store call back we can remove data from storeArray or maintain a veribale for checking.
Ext.Array.remove(storeArry, this.storeId);
if (storeArry.length == 0) {
Ext.Msg.alert('Success', 'All stored is loaded..!');
}
}
});
});
}, 3000);
是否'isLoading()''等於沒有裝入存儲時FALSE'?這可能是一個問題嗎? –
@o_nix by「not loaded」你的意思是「沒有記錄」?根據我的經驗,'isLoading'只在從服務器發出請求和響應之間的時間內等於true。所以如果服務器沒有返回記錄,那麼它仍然是真的。這對我來說從來都不是問題。它的主要觀點是簡單地知道請求何時返回。如果你想處理沒有結果的響應,可以實現不同的邏輯。 – Geronimo
爲了保持檢查可能setTimeout(me.initData,500)應該工作。 – VAAA