PDA

View Full Version : store proxy extraparams issue



ttbgwt
30 Aug 2012, 4:25 AM
I defined a store that uses a proxy that has some extraParams defined.

In my code I create two instances of the store and change/add some extraParams on the attached proxy.

My problem is that the last store that gets created, its extraParams proxy changes are used in both stores. It seems that the last store instance created overwites the changed proxy setttings on the first created store.

proxy definition:


Ext.define('MYAPP.proxy.TagFieldOptions', {
extend: 'MYAPP.proxy.Base',
alias : 'proxy.proxytagfieldoptions',
url: MYAPP.URL.getTagFieldOptionsUrl(),
extraParams: {
dir: 'ASC',
accept: 'application/json'
},
constructor: function (config) {

var me = this;
Ext.apply(me, config);
me.callParent(arguments);
}
});


store definition:


Ext.define('MYAPP.store.TagFieldOptions', {


extend: 'Ext.data.Store',
requires: [
'MYAPP.proxy.TagFieldOptions'
],
model: 'MYAPP.model.TagFieldOption',
autoLoad: true,
autoSync: false,
remoteSort: true,
remoteFilter: true,
remoteGroup: true,
buffered: false,


proxy: {
type: 'proxytagfieldoptions'
},


constructor: function (config) {
var me = this;
Ext.apply(me, config);


//if store is configured with extraParams, then set those into the proxy
if (config.extraParams !== undefined) {
if (me.getProxy().extraParams === undefined) {
me.getProxy().extraParams = config.extraParams;
} else {
Ext.apply(me.getProxy().extraParams, config.extraParams);
}
}
me.callParent(arguments);
}
});


store used for combobox one:


store: Ext.create('MYAPP.store.TagFieldOptions', {
extraParams: {
field: 'abc'
}
}),


store used for combobox two:


store: Ext.create('MYAPP.store.TagFieldOptions', {
extraParams: {
field: 'xyz'
}
}),


Both of the above store make the call to get data but both use the extraParam of field = 'xyz' as 'abc' is overwritten by second store.

tvanzoelen
30 Aug 2012, 4:42 AM
Yes, because you must define the extraParams in the constructor.

Now its is set on the prototpye, so it is shared by each instance of that class.



Ext.define('MYAPP.proxy.TagFieldOptions', {
extend: 'MYAPP.proxy.Base',
alias : 'proxy.proxytagfieldoptions',
url: MYAPP.URL.getTagFieldOptionsUrl(),

constructor: function (config) {

this.extraParams = {
dir: 'ASC',
accept: 'application/json'
};

var me = this;
Ext.apply(me, config);
me.callParent(arguments);
}
});


see this post: http://www.sencha.com/forum/showthread.php?152606-Class-properties-are-in-someway-global