-
26 Nov 2012 12:37 AM #1
Answered: Store global load event in MVC
Answered: Store global load event in MVC
I want to listen on load of all stores. Is there a way I can do it in a MVC structure? :x
I already thought about extending from the 'Ext.data.Store' class, but it wont work, because the class extinding it needs to be a store itself. So I read about the observable class, but this seems to be the wrong way too...
I don't want to register a load listener for each store I have... I would lik eto have global load listener.
-
Best Answer Posted by slemmon
I tested just now with the following and it worked for me (using ExtJS 4.1.1a - I think you need 4.1.1 or higher for Ext.application's init method to fire - was a bug fix)
inside my Ext.application - moved setting up the global variable.app (MYAPP.app) to the init function of Ext.application instead.
Now from any controller you can add a listener for 'storeload'. The below snippet I put in one of my controller's init functionCode:init: function () { var me = this; MYAPP.app = me; Ext.data.StoreManager.on('add', function (i, store) { store.on('load', function () { // or datachanged or whatever you want LARGE.app.fireEvent('storeload', store); }); }); }
That's how I saw ... I think Tommy Maintz ... can't remember ... fire and handle application level events and it's worked well for me.Code:me.application.on('storeload', function (store) { console.log(store); });
-
27 Nov 2012 12:39 PM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
Ajax proxy uses Ext.Ajax to load things so you can hook into Ext.data.Connection where it does the actual XHR request.
Mitchell Simoens @SenchaMitch
Sencha Inc, Senior Forum Manager
________________
http://www.JSONPLint.com - Source to lint your JSONP!
Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
https://github.com/mitchellsimoens
Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/
Need more help with your app? Hire Sencha Services services@sencha.com
Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is almost in print!
When posting code, please use BBCode's CODE tags.
-
27 Nov 2012 11:47 PM #3
Great idea, I will try that and maybe post how I did it ^^
Thx =)
-
28 Nov 2012 4:03 AM #4
Hmmm.... seems that this method isn't working for my usecase. The idea behind that is, that I want to create dependencies between stores. Means, if store 1 loads it should automaticly load store 2 too. For that I want to add an array in the stores with depedent stores. So I would need to have the actual store which is loading data. I can't figure out how I should get the store in the Ext.data.Connection class. =/
-
28 Nov 2012 7:54 AM #5
I might be off-base here and I haven't tested it, but what about:
Code:Ext.data.StoreManager.on('add', function (i, store) { store.on('load', function () { MYAPP.app.fireEvent('storeload', o); }); }); Ext.application({ name: 'MYAPP' , launch: function () { var me = this; MYAPP.app = me; // a trick I learned from Mitchell } });
-
28 Nov 2012 8:14 AM #6
Very interesting, but where to go with:
I tried:Code:Ext.data.StoreManager.on('add', function (i, store) { store.on('load', function () { MYAPP.app.fireEvent('storeload', o); }); });
Code:launch: function() { CMS.app = this; Ext.create('CMS.library.data.StoreLoader'); }Code:Ext.define('CMS.library.data.StoreLoader', { constructor: function() { Ext.data.StoreManager.on('add', function (i, store) { store.on('load', function () { console.log('muh'); CMS.app.fireEvent('storeload'); }); }); } });
but it doesn't work...
-
28 Nov 2012 10:08 AM #7
I tested just now with the following and it worked for me (using ExtJS 4.1.1a - I think you need 4.1.1 or higher for Ext.application's init method to fire - was a bug fix)
inside my Ext.application - moved setting up the global variable.app (MYAPP.app) to the init function of Ext.application instead.
Now from any controller you can add a listener for 'storeload'. The below snippet I put in one of my controller's init functionCode:init: function () { var me = this; MYAPP.app = me; Ext.data.StoreManager.on('add', function (i, store) { store.on('load', function () { // or datachanged or whatever you want LARGE.app.fireEvent('storeload', store); }); }); }
That's how I saw ... I think Tommy Maintz ... can't remember ... fire and handle application level events and it's worked well for me.Code:me.application.on('storeload', function (store) { console.log(store); });Last edited by slemmon; 28 Nov 2012 at 10:10 AM. Reason: changed datachanged event to load
-
29 Nov 2012 12:01 AM #8
Yay, worx ^^
How I did it:
app.js
StoreLoader.jsCode:Ext.application({ name: 'CMS', appFolder: '../bundles/extjs/app', controllers: [ //Andere 'CMS.controller.StoreLoader' ], autoCreateViewport: true, init: function () { var me = this; CMS.app = me; Ext.data.StoreManager.on('add', function (i, store) { store.on('load', function () { CMS.app.fireEvent('storeload', store); }); }); }, /** * Wird aufgerufen, sobald ie Application bereit ist * * @return void */ launch: function() { } });
Thx! =DCode:Ext.define('CMS.controller.StoreLoader', { extend: 'CMS.controller.AbstractController', init: function() { var me = this; me.application.on('storeload', function (store) { console.log(store); }); } });


Reply With Quote