1. #1
    Ext JS Premium Member tangix's Avatar
    Join Date
    Mar 2010
    Location
    Stockholm, Sweden
    Posts
    560
    Vote Rating
    50
    tangix is a jewel in the rough tangix is a jewel in the rough tangix is a jewel in the rough

      0  

    Default Unanswered: Are Stores sharing the same Model objects?

    Unanswered: Are Stores sharing the same Model objects?


    In my app I have the need to display grids of redeemed/non-redeemed vouchers. I setup one Model ("VoucherModel") and configures two JsonP Stores - one for redeemed and one for non-redeemed and ties them up to the VoucherModel. The VoucherModel contains the JsonP Proxy to point to the server. The grids are displayed on separate tabs so I'd like to load them when needed.

    When the user logs in I setup the stores with the URLs:
    Code:
    Ext.getStore('ActiveVoucherStore').getProxy().url = UP8.config.backend + 'voucher/active';
    Ext.getStore('RedeemedVoucherStore').getProxy().url = UP8.config.backend + 'voucher/redeemed';
    The actual result is however that both stores loads the redeemed voucher, leading me to suspect that the Stores shares the Model object.
    I have worked around this by defining the JsonP Proxy directly on each Store and it now works - but will the shared Model bite me later?

    Thanks,
    /Mattias

  2. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,078
    Answers
    674
    Vote Rating
    467
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    How are you defining your models? Are you placing the details (proxy,etc) in a constructor so they both can create their own instance?

    Scott.

  3. #3
    Ext JS Premium Member tangix's Avatar
    Join Date
    Mar 2010
    Location
    Stockholm, Sweden
    Posts
    560
    Vote Rating
    50
    tangix is a jewel in the rough tangix is a jewel in the rough tangix is a jewel in the rough

      0  

    Default


    I'm using Sencha Architect to create the Model and bind to the Stores. Maybe this is the problem - as I have defined the proxy on the Model I simply deleted it from the Store... I'll try to add the Ext.data.proxy.JsonP to each of the Stores and delete it from the Model.
    Code:
    Ext.define('MyApp.model.VoucherModel', {
        extend: 'Ext.data.Model',
        alias: 'model.vouchermodel',
    
        proxy: {
            type: 'jsonp',
            reader: {
                type: 'json'
            }
        }
    });
    The Store's code is generated as:
    Code:
    Ext.define('MyApp.store.RedeemedVoucherStore', {
        extend: 'Ext.data.Store',
        alias: 'store.redeemedvoucherstore',
    
        requires: [
            'MyApp.model.VoucherModel'
        ],
    
        constructor: function(cfg) {
            var me = this;
            cfg = cfg || {};
            me.callParent([Ext.apply({
                storeId: 'MyJsonPStore1',
                model: 'MyApp.model.VoucherModel',
                proxy: {
                    type: 'jsonp',
                    reader: {
                        type: 'json'
                    }
                }
            }, cfg)]);
        }
    });

Thread Participants: 1