PDA

View Full Version : Ext.data.proxy.Ajax gets wrong model upon store creation



mx_starter
8 Jul 2014, 1:54 AM
Well guys,
i'm not sure if this is a bug or an expected behaviour, but look at this fiddle:

7fs

What is within:
1. Definitions for 2 models - 'app.Reports.Models.model-1' and 'app.Reports.Models.model-2'
2. The store definition (without the model config) - 'app.Grids.Stores.gridTreeStore'
3. 2 buttons with a handler function (createStore), which receives the model names depending upon which button is clicked.

What the handler function does is:
1. If the store is presented in the StoreManager - destroy it using its destroyStore() method.
2. Get the needed model from the ModelManager depending on the button clicked
3. Create the store using the needed model, which is passed as a config with Ext.create()
4. Finally - alert the modelName of the store's proxy (instead of the name of the model of the store itself)

So - if you click the first button, you expect to see that the target Proxy model is 'app.Reports.Models.model-1' and if you click the second one - 'app.Reports.Models.model-2'.

However - the alert message always shows the model of the first button clicked???

Note that the store itself receives the right model, but its proxy - does not.

I suspect that the problem is with the proxy definition (it is defined as a config within the store definition), but can not explain myself why this happens.
A similar problem is described here, specifically look at the mitchelsimoens' answer:
http://www.sencha.com/forum/showthread.php?154088

I'll be glad if someone can explain it, cheers!

evant
8 Jul 2014, 2:04 AM
Because the proxy is on the prototype, it means the objects get shared across instances. Move the creation of the proxy object inside the store constructor.

mx_starter
8 Jul 2014, 3:01 AM
Because the proxy is on the prototype, it means the objects get shared across instances. Move the creation of the proxy object inside the store constructor.

Evant, you mean like this (check the updated fiddle):


Ext.define('app.Grids.Stores.gridTreeStore', {
extend: 'Ext.data.TreeStore',
storeId: 'reportStore',
autoDestroy: true,
autoLoad: false,
proxy: Ext.create('Ext.data.proxy.Ajax', {
type: 'ajax',
url: 'scripts/grid/php/populateGrid.php',
async: false,
actionMethods: {
read: 'POST'
},
timeout: 120000,
reader: {
type: 'json',
root: 'RECORDS'
}
})


If so - does it means that if i do not use Ext.create() for the proxy, destroying the store will not destroy the previously autocreated proxy?

mx_starter
8 Jul 2014, 3:14 AM
And browsing around, i feel this is a common misunderstanding across unexperienced Ext users like me.
Where in the docs can we read about the logic of the inheritance?