PDA

View Full Version : cannot listen beforeprefetch event



ferengidedalo
17 Oct 2011, 5:32 AM
I have this code in a store definition:


initComponent: function(){
this.addListener('beforeprefetch', this.onBeforePrefetch, this);
this.superclass.initComponent.call(this, arguments);
},

onBeforePrefetch: function(store,operation,options){
console.log(store);
}


but function is not logging anything when the data is loaded into a grid using this store... anyhelp?

skirtle
17 Oct 2011, 1:42 PM
Stores don't have an initComponent method. Only components have initComponent. Override the constructor instead.

Also, this line has some issues:


this.superclass.initComponent.call(this, arguments);

Firstly, it's a subclassing nightmare. If you subclass this store it'll get into an infinite loop because this.superclass.initComponent will refer to itself.

Secondly, you've used call with arguments. It should really be apply, not call. This point is moot though as initComponent doesn't take any arguments anyway.

Thirdly, the correct way to call a superclass's overridden implementation of a method in ExtJS 4 is:


this.callParent();

or:


this.callParent(arguments);

In the case of initComponent I'd use the former as it doesn't take any arguments.