-
12 Nov 2012 6:03 AM #1
Answered: Waiting for until Store is loaded not work
Answered: Waiting for until Store is loaded not work
Hi,
i have a problem with loading my config store before my appication start.
normal output:Code: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); }
but often only this and the vesion field stay empty:Code:before load configStore load configStore version: v1.0
Code:before load configStore
-
Best Answer Posted by Farish
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.
Code:store = new Ext.data.Store({ autoLoad: true, listeners: { load: function() { console.log("store loaded"); } } });
-
12 Nov 2012 6:24 AM #2Ext JS Premium Member
- Join Date
- Apr 2008
- Location
- Groningen - Netherlands
- Posts
- 1,017
- Vote Rating
- 23
- Answers
- 75
Strange but earlier in previous versions it did matter if the number of parameters were correct
Code: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"); } });
-
12 Nov 2012 6:25 AM #3Sencha - Community Support Team
- Join Date
- May 2012
- Location
- Istanbul
- Posts
- 1,331
- Vote Rating
- 76
- Answers
- 124
Hi Roman_s,
Put a debugger after the getStore('configStore') and check configStore have your store reference.sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.
-
12 Nov 2012 6:46 AM #4
Yes, the configStore has a reference.
Now I have disabled the autoload property of the store and it seems to work
Code: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"); } });
-
12 Nov 2012 7:06 AM #5
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.
Code:store = new Ext.data.Store({ autoLoad: true, listeners: { load: function() { console.log("store loaded"); } } });
-
12 Nov 2012 7:19 AM #6
Thanks, this solution works too.Code:store = new Ext.data.Store({ autoLoad: true, listeners: { load: function() { console.log("store loaded"); } } });
-
12 Nov 2012 9:20 AM #7Sencha - Sales Team
- Join Date
- Mar 2007
- Location
- Melbourne, Australia (aka GMT+10)
- Posts
- 738
- Vote Rating
- 6
- Answers
- 10
also good to note that listeners should be in your controllers using best practice ExtJS 4.x
Check out SenchaWorld.com for articles, screencasts, conference videos and more.
Sencha Technical Training : Asia Pacific Region
Code Validation : JSLint | JSONLint | JSONPLint


Reply With Quote



