mardi 1 juillet 2014

Store and Listeners

Hi,

I need to add listeners to a Store. I want to do some special processing in the "load" event.

In the Documentation we can read




listeners : Object

A config object containing one or more event handlers to be added to this object during initialization. This should be a valid listeners config object as specified in the addListener example for attaching multiple handlers at once.


See the Event guide for more


Note: It is bad practice to specify a listener's config when you are defining a class using Ext.define(). Instead, only specify listeners when you are instantiating your class with Ext.create().





I don't understand why **It is a bad practice**

I have a View associated with it's ViewController and I would like to keep the special processing in the store and not bother the View nor the ViewController.


I instantiate the store in my view but I don't want to define a listener in my view nor in my controller.


I have specified in the definition of my Store the listener that I need, but some how the my listener is not called. What am I doing wrong?



Code:



Ext.define('My.store.WeeklyHours', {
extend: 'Ext.data.Store'
,model: 'My.model.Entry'
,storeId: 'WeeklyHours'
,remoteSort: false
,proxy: {
type: 'ajax'
,api: {
read: 'data/user/week/entries'
}
,reader: {
type: 'json'
,rootProperty: 'results'
,totalProperty: 'totalCount'
}
}
,listeners: [
{
fn: this.onLoadStore,
event: 'load',
scope:this
}
]
,onLoadStore: function() {
var proxy = this.getProxy()
var reader = proxy.getReader()
var rawData = reader.rawData
....

Thanks for your help.


Aucun commentaire:

Enregistrer un commentaire