PDA

View Full Version : AJAX proxy does not work with Ext.data.ArrayStore



pmonteir
28 Mar 2012, 9:38 PM
I am using the MVC architecture.
I have created an ArrayStore which is wrapped inside a Ext.view.View - SummaryView


Ext.define('MY.system.store.Summary', {
extend: 'Ext.data.ArrayStore',
requires: 'MY.system.model.Summary',
model: 'MY.system.model.Summary',
data: [
],

proxy: {
type: 'ajax',
url : '/my/summary'
}
});


And I am trying to load this store from my Controller using:


this.getSummaryView().getStore().load()


Using Firebug, I noticed that on calling store.load() there is no AJAX request being called to my server.
However, if I change my Store definition to extend Ext.data.Store, then on store.load(), the AJAX request can be seen in the Firebug console.

Is this a bug with the ArrayDataStore?

Regards,
Prashant

vietits
28 Mar 2012, 10:52 PM
It is because the proxy you defined in MY.system.store.Summary will be override by proxy {type: 'memory', reader: 'array'} in Ext.data.ArrayStore.constructor().


Ext.define('MY.system.store.Summary', {
extend: 'Ext.data.ArrayStore',
requires: 'MY.system.model.Summary',
model: 'MY.system.model.Summary',
data: [ ],
proxy: {
type: 'ajax',
url : '/my/summary'
}
});

You can fix this problem as follow:


Ext.define('MY.system.store.Summary', {
extend: 'Ext.data.ArrayStore',
requires: 'MY.system.model.Summary',
model: 'MY.system.model.Summary',
constructor: function(config){
config = config || {};
Ext.applyIf(config, {
data: [ ],
proxy: {
type: 'ajax',
url : '/my/summary',
reader: 'array'
}
});
this.callParent(config);
}
});

However, ArrayStore is a small helper class to make creating Ext.data.Stores from Array data easier. It is extended from Ext.data.Store with proxy set to {type: 'memory', reader: 'array'}. It is suitable for use directly instead of use as base class to extend. I suggest you extend your store class from Ext.data.Store.

pmonteir
29 Mar 2012, 12:03 AM
Thanks for the reply. It helped.
Im extending DataStore and it works.

Regards,
Prashant