-
2 Oct 2012 6:21 AM #1
Unanswered: How to notify a view that a store has been refreshed ?
Unanswered: How to notify a view that a store has been refreshed ?
I am trying to make a store to notify a view whenever it's been refreshed. (For various reasons I would prefer not to use a DataView.) I thought I could do it like this:
In the store I declare a custom event myEvent and have the refresh handler fire it on the app to make it global:
and then have the view listen for myEvent:Code:Ext.define('MyApp.store.MyStore', { extend: 'Ext.data.Store', config: { ... listeners: [ { fn: 'onDirectstoreRefresh', event: 'refresh' }, { fn: 'onDirectstoreMyEvent, event: 'myEvent' } ] }, onDirectstoreRefresh: function(store, data, eOpts) { MyApp.app.fireEvent('myEvent', this, 0); }, onDirectstoreMyEvent: function(eventOptions) { console.log('MyEvent received in MyStore'); // This bit works } });
myEvent is received inside the store but it never gets to the view. What have I missed out ?Code:Ext.define('MyApp.view.root', { extend: 'Ext.Container', config: { ... listeners: [ { fn: 'onContainerMyEvent', event: 'myEvent' } ] }, onContainerMyEvent: function(container) { console.log('MyEvent received in view'); // This never happens } });
Thanks in advance.
-
4 Oct 2012 7:14 AM #2Sencha - Senior Forum Manager
- Join Date
- Mar 2007
- Location
- St. Louis, MO
- Posts
- 33,656
- Vote Rating
- 435
- Answers
- 3108
In the view, you should add listeners to the store
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.
-
4 Oct 2012 11:27 AM #3
@Mitchell, Thanks for suggesting the preferred pattern. Is there a material difference between using the view's listeners config vs. using this.on('myEvent',doSomething) in an overridden constructor?
-
7 Oct 2012 10:42 PM #4
Thanks, this is working now.
In MyView I put
Code:listeners: [ { fn: 'onContainerInitialize', event: 'initialize' } ]
and
andCode:onContainerInitialize: function(component, options) { this.store = Ext.data.StoreManager.lookup('MyStore'); this.store.addListener('refresh', this.onMyStoreRefresh, this, {order: 'after'} ); this.store.fireEvent('refresh'); }
I'm not trying to use a global event anymore.Code:onMyStoreRefresh: function(component) { console.log(store refreshed'); ... }
-
7 Oct 2012 11:19 PM #5
In your op, you wrote
'MyApp.app' is the instance of 'Application',not your 'view'.Code:MyApp.app.fireEvent('myEvent', this, 0)
This is the reason why 'This never happens'.
Add listener to your application object or fire event by your view is the correct way.I write English by translator.


Reply With Quote