Results 1 to 4 of 4

Thread: Ext.data.proxy.Ajax gets wrong model upon store creation

  1. #1
    Sencha User
    Join Date
    Dec 2008
    Location
    Sofia
    Posts
    267

    Default Ext.data.proxy.Ajax gets wrong model upon store creation

    Well guys,
    i'm not sure if this is a bug or an expected behaviour, but look at this fiddle:



    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!

  2. #2
    Sencha Premium User evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    19,258
    Answers
    759

    Default

    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.
    Twitter - @evantrimboli
    Former Sencha framework engineer, available for consulting.
    As of 2017-09-22 I am not employed by Sencha, all subsequent posts are my own and do not represent Sencha in any way.

  3. #3
    Sencha User
    Join Date
    Dec 2008
    Location
    Sofia
    Posts
    267

    Default

    Quote Originally Posted by evant View Post
    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):
    Code:
    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?

  4. #4
    Sencha User
    Join Date
    Dec 2008
    Location
    Sofia
    Posts
    267

    Default

    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?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •