Reputation: 972
I have 2 stores, one contains permissions and the other contains data to be displayed in the Grid. But there is a piece of code in my file that has to be executed only after these 2 stores are loaded. Currently in my code with out this condition check there is no guarantee that the stores are loaded before the critical piece of code is executed
Upvotes: 1
Views: 1693
Reputation: 454
Why don't you just listen both stores load
event?
When you load a store, you flip its flag. When both flags are switched, you call your critical code.
{
firstLoaded: false,
secondLoaded: false,
initComponent: function(){
...
firstStore.on('load', function(){ this.firstLoaded=true; this.check(); }, this);
secondStore.on('load', function(){ this.secondLoaded=true; this.check(); }, this);
...
},
check: function(){
if (this.firstLoaded && this.secondLoaded) {
this.initializeLSEngine();
}
},
initializeLSEngine: function(){
...
}
}
Eventually add {single:true}
to both .on
if needed.
Upvotes: 1
Reputation: 1291
Using Extjs, I guess you will have to make use of the callback method.
ExtJs store comes with load callback method. You can load one store first, once it is loaded, then start another store's loading, finally you will be able to know there two stores are both loaded.
Upvotes: 0