PDA

View Full Version : Waiting for until Store is loaded not work



Roman_S
12 Nov 2012, 6:03 AM
Hi,

i have a problem with loading my config store before my appication start.



var configStore = Ext.getStore("configStore");

try{

console.log("before load configStore");

configStore.on('load', function(){

console.log("load configStore");
var data = this.getAt(0).getData();

console.log("version: " + data.logo);
Ext.ComponentQuery.query("#versionLabel")[0].setText(data.version);
});

}catch(err){
console.log(err);
}

normal output:



before load configStore
load configStore
version: v1.0



but often only this and the vesion field stay empty:



before load configStore

tvanzoelen
12 Nov 2012, 6:24 AM
Strange but earlier in previous versions it did matter if the number of parameters were correct



configStore.on('load', function(store, records, successful, eOpts ){

console.log("load configStore");
var data = records;

if(successful && store.getCount() > 0){
console.log("version: " + data[0].get('logo');
Ext.ComponentQuery.query("#versionLabel")[0].setText(data[0].get('version'));
}
else{
console.log("no records");
}

});

sword-it
12 Nov 2012, 6:25 AM
Hi Roman_s,

Put a debugger after the getStore('configStore') and check configStore have your store reference.

Roman_S
12 Nov 2012, 6:46 AM
Hi Roman_s,

Put a debugger after the getStore('configStore') and check configStore have your store reference.

Yes, the configStore has a reference.

Now I have disabled the autoload property of the store and it seems to work



var configStore = Ext.getStore("configStore");
configStore.load();

configStore.on('load', function(store, records, successful, eOpts){

console.log("load configStore");
var data = records;

if(successful && store.getCount() > 0){
Ext.ComponentQuery.query("#versionLabel")[0].setText(data[0].get('version'));
}
else{
console.log("configstore records could not be loaded");
}

});

Farish
12 Nov 2012, 7:06 AM
the problem seems to be that the listener is not added to the store when the store is being loaded the first time (on autoLoad: true). To fix this, you can use the listeners config and directly add the listener in the store.


store = new Ext.data.Store({
autoLoad: true,
listeners:
{
load: function()
{
console.log("store loaded");
}
}
});

Roman_S
12 Nov 2012, 7:19 AM
store = new Ext.data.Store({
autoLoad: true,
listeners: {
load: function() {
console.log("store loaded");
}
}
});

Thanks, this solution works too.

dawesi
12 Nov 2012, 9:20 AM
also good to note that listeners should be in your controllers using best practice ExtJS 4.x