PDA

View Full Version : Store using another store's reader instead of it's own



Brett89
12 Apr 2012, 10:20 PM
So I define a custom proxy like so:




Ext.define('CustomProxy', {
alias: 'proxy.custom',
extend: 'Ext.data.proxy.Ajax',
reader: {
type: 'json',
root: 'defaultRoot'
}
});



And I instantiate two stores using that proxy:




var myStore = Ext.create('Ext.data.Store', {
storeId: 'myStore',
model: 'myModel',
proxy: {
type: 'custom',
url: 'myUrl.asmx'
}
});


var myOtherStore = Ext.create('Ext.data.Store', {
storeId: 'myOtherStore',
model: 'myOtherModel',
proxy: {
type: 'custom',
url: 'myOtherUrl.asmx'
}
});



So all I've done with the proxy is added a url. It appears that myOtherStore is actually using the reader of myStore. Can someone explain to me what's going on?

vietits
12 Apr 2012, 11:31 PM
Because you don't define reader for both store objects so they will use the default one defined in CustomProxy. However, in CustomProxy, you define reader as an object and it will be shared at CustomProxy prototype so any store that does not have its own reader will share the same default reader. Below is my suggestion to avoid this.


Ext.define('CustomProxy', {
alias: 'proxy.custom',
extend: 'Ext.data.proxy.Ajax',
constructor: function(config){
var me = this;
config = Ext.applyIf(config, {
reader: {
type: 'json',
root: 'defaultRoot'
}
});
me.callParent(arguments);
}
});

Brett89
15 Apr 2012, 5:25 PM
Exactly what I wanted. Thank you.