Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var store1Loaded = false;
- var store2Loaded = false;
- store1.on('load', function(){
- store1Loaded = true;
- });
- store2.on('load', function(){
- store1Loaded = true;
- });
- store1.load();
- store2.load();
- function WaitForFunction()
- {
- if (!store1Loaded || !store2Loaded)) {
- setTimeout( WaitForFunction, 100);
- return;
- }
- AllStoresLoaded();
- }
- function AllStoresLoaded(){
- //Do Something
- }
- var store1 = Ext.create('Ext.data.Store', {
- model: myModel,
- storeId: 'store1', // store needs to be done MVC style or have this config
- proxy: {
- type: 'ajax',
- url: 'url...',
- reader: 'json'
- },
- autoLoad: {
- callback: initData // do this function when it loads
- }
- });
- var store2 = Ext.create('Ext.data.Store', {
- model: myModel,
- storeId: 'store2',
- proxy: {
- type: 'ajax',
- url: 'url...',
- reader: 'json'
- },
- autoLoad: {
- callback: initData // do this function when it loads
- }
- });
- // the stores to be checked
- var myComboStores = ['store1', 'store2']
- // function does logic if they are both finished loading
- function initData() {
- var loaded = true;
- Ext.each(myComboStores, function(storeId) {
- var store = Ext.getStore(storeId);
- if (store.isLoading()) {
- loaded = false;
- }
- });
- if(loaded) {
- // do stuff with the data
- }
- }
- var allStores = [store1, store2],
- len = allStores.length,
- loadedStores = 0,
- i = 0;
- for (; i < len; ++i) {
- allStores[i].on('load', check, null, {single: true});
- }
- function check() {
- if (++loadedStores === len) {
- AllStoresLoaded();
- }
- }
- function AllStoresLoaded() {
- //Do Something
- }
- function storeLoadingHandler(justLoadedStore) {
- // I use some quick hacky flag, you can do it by your own way
- justLoadedStore.loaded = true;
- var allStoresLoaded = true;
- // just walk through all stores registered in the application
- // do not forget to use MVC-style stores or add 'storeId' manually
- // or register every store with your custom code
- Ext.StoreManager.each(function(existingStore) {
- // we have to ignore system stores
- if (existingStore.storeId != 'ext-empty-store') {
- if (!existingStore.loaded) { // our flag or undefined
- // nope, at least one of stores is not loaded
- allStoresLoaded = false;
- return false
- }
- }
- })
- if (allStoresLoaded) // then do something
- alert('All stores are loaded.');
- }
- // add the loading handler for all stores
- Ext.StoreManager.each(function() {
- this.on('load', storeLoadingHandler);
- })
- Ext.create("Ext.data.Store", {
- ...,
- loading: true,
- ...
- });
- 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'
- }
- }
- });
- }
- var storeArry = [],
- store = '';
- for (var key = 0; key < 5; key++) {
- storeArry.push(createStore(key).storeId);
- }
- 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);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement