PDA

View Full Version : Extending a directStore which includes a reader



mkraemer
2 Aug 2010, 6:14 AM
Hi,

what i'm trying to achieve is to create a custom store which includes a reader.
I'm able to break it to the following minimal example:


testStore = Ext.extend(Ext.data.DirectStore, {
reader: new Ext.data.JsonReader(),
writer: new Ext.data.JsonWriter()
});An instance of the resulting store has the expected writer attribute, but the reader attribute is undefined. What am i missing here?

What i've also tried is to assign the reader in the constructor method of my store:

testStore2 = Ext.extend(Ext.data.DirectStore, {
constructor: function(){
Ext.apply(this, {
reader: new Ext.data.JsonReader()
});
testStore2.superclass.constructor.apply(this, arguments);
},
writer: new Ext.data.JsonWriter()
});In this case, the resulting store has a reader, but only as long as i don't call the constructor of his superclass (marked red).

It would be great if someone could point me in the right direction here.. thank you :)

Condor
2 Aug 2010, 7:36 AM
A DirectStore is nothing more than a Store with a preconfigured DirectProxy and a JsonReader.

If you want to specify your own proxy or reader, then why not start with a normal Store instead of a DirectStore?

mkraemer
2 Aug 2010, 7:53 AM
Ah, thank you Condor. Extending a normal store works perfectly.

Just out of curiosity, why did my approach fail? Shouldn't i be able to overwrite the reader in the constructor?

Condor
2 Aug 2010, 8:00 AM
No, the reader will be replaced by the superclass (=DirectStore) constructor.