PDA

View Full Version : Loading Stores In Sequence



azinyama
24 Aug 2012, 5:02 AM
Good day all!!!

I need some help with an application I'm developing.

I have 8 stores that I want to load in a particular order; say: store01, store02, store03, store04, ..., store08.
What I'm trying to get is for store01 to load; wait until it has finished loading then load store02; wait until it has finished loading then load store03; and so on and so on, until store08 has finished loading.

How would I bee able to do this???
Thanx in advance for your help...:D

vietits
24 Aug 2012, 5:26 AM
Try this:


function loadStores(stores, index){
if(index < stores.length){
stores[index].load({
callback: function(){
loadStores(stores, ++index)
}
});
}
}
loadStores([store01, store02, store03,...], 0);

azinyama
24 Aug 2012, 11:52 AM
Thanks a lot for the reply. Just tried out your solution and it worked just the way I wanted it to. I just changed it a bit to work with the controller I'm working with.
Another question if it's not to much trouble.
I want to add a delay between each load. e.g. Load store01, wait 3sec, load store02, wait 3sec, load store03... and so on and so on...
Below is what I have inside my controler:




stores :
[
'store01',
'store02',
'store03',
'store04',
'store05',
'store06',
'store07',
'store08',
'store09'
],

init: function()
{
this.control({
'desktopWindow':
{
render: this.onRender
}
});
},

onRender: function()
{
this.loadStores(this.stores, 0);
},

loadStores: function(stores, index)
{
if(index < stores.length)
{
console.log(stores[index]);
Ext.data.StoreManager.lookup(stores[index]).load(
{
callback: function()
{
this.loadStores(stores, ++index)
},
scope: this
}, this);
}
}


I stuck at getting the call back to execute with a time delay...

azinyama
24 Aug 2012, 1:28 PM
Hey.
This is what I have done. I changed the function you gave me to look like this. Is this ok, or is there a better way of doing this???



loadStores: function(stores, index)
{
var onLoadTask = null;

if(index < stores.length)
{
var store = Ext.data.StoreManager.lookup(stores[index]);

store.on('beforeload', this.onBeforeLoad, this);
store.on('load', this.onLoad, this);

store.load(
{
callback: function()
{
onLoadTask = new Ext.util.DelayedTask(function()
{
this.loadStores(stores, ++index);
}, this);

onLoadTask.delay(5000);
},
scope: this
}, this);

return;
};

onLoadTask = null;

this.getDesktopStatusBar().setStatus({text: 'Ready...', iconCls: 'x-status-valid'});
}

vietits
24 Aug 2012, 3:25 PM
It's better to use Ext.defer():


loadStores: function(stores, index)
{
// var onLoadTask = null;

if(index < stores.length)
{
var store = Ext.data.StoreManager.lookup(stores[index]);

store.on('beforeload', this.onBeforeLoad, this);
store.on('load', this.onLoad, this);

store.load(
{
callback: function()
{
// onLoadTask = new Ext.util.DelayedTask(function()
// {
// this.loadStores(stores, ++index);
// }, this);
//
// onLoadTask.delay(5000);
Ext.defer(this.loadStores, 5000, this, [stores, ++index]);
},
scope: this
}, this);

return;
};

// onLoadTask = null;

this.getDesktopStatusBar().setStatus({text: 'Ready...', iconCls: 'x-status-valid'});

azinyama
25 Aug 2012, 5:30 AM
Thanx a lot for your help. Tried your solution. Worked like a charm.

=D>