PDA

View Full Version : Proxy on Model/Store



johanhaest
31 May 2012, 3:38 AM
Problem:
I want to have my proxy's on the model, because i can call the .save() method on the model itself. Problem with this is that I have a store with that model. If i then instantiate 2 stores they both share the same proxy. When I put the proxy on the store and instantiate 2 stores they don't have the same proxy.

I want a different proxy so I can send extraParams to the backend unique to the instantiated store;

Code example:

Proxy on Model


var store1 = Ext.create('App.store.TestStore');
var store2 = Ext.create('App.store.TestStore');

store1.getProxy().extraParams = { code: 21};
store2.getProxy().extraParams = { code: 24};

alert(store1.getProxy().extraParams.code) //24 will appear


Proxy on Store


var store1 = Ext.create('App.store.TestStore');
var store2 = Ext.create('App.store.TestStore');

store1.getProxy().extraParams = { code: 21};
store2.getProxy().extraParams = { code: 24};

alert(store1.getProxy().extraParams.code) //21 will appear


Any alternative ways?

sdt6585
31 May 2012, 4:25 AM
You might be able to create your proxies in the constructor for each store. I'm pretty sure Ext won't override a store's defined proxy with the one in the model. Just reference the model's proxy when creating the store's (ie. url = model.proxy.url) for everything except the extra params properties where you can do your customization. You will have to pass a variable in the config object on Ext.create for this to work --
var store1 = Ext.create('App.store.TestStore', {extraParams: {code: 21} });
-- then set extraParams = config.extraParams in the constructor for the proxy.

johanhaest
31 May 2012, 5:53 AM
I've been testing and it seems like i'll have to try your idea sdt6585.

johanhaest
31 May 2012, 6:39 AM
This fixed it for me:



Ext.define('App.store.TestStore', {
extend: 'Ext.data.Store',
model: 'App.model.TestModel',


constructor: function (config) {
var lMe = this;
lMe.callParent(this);


//clone proxy
var lProxy = Ext.Object.merge({}, lMe.getProxy());
lMe.setProxy(lProxy);
}
});