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);