Results 1 to 4 of 4

Thread: unable to display data from nested store/model

  1. #1
    Sencha User
    Join Date
    May 2010
    Posts
    14
    Answers
    1

    Default Answered: unable to display data from nested store/model

    Hello, im trying to display nested data on two different grids.

    this is the json that im getting from the backend

    Code:
    {"balancers":[{"name":"test","members":[{"gw":"foo1","score":"1"},{"gw":"foo2","score":"9"}]},{"name":"bal2","members":[{"gw":"2foo1","score":"1"},{"gw":"2foo2","score":"9"}]}],"msg":null,"total":2,"success":true}
    Then i have the models

    Code:
    Ext.define('sfe.model.Balancer', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'name', type: 'string'}
        ],
        idProperty: 'name',
        associations: [
            { type: 'hasMany', model: 'sfe.model.BalancerMember', name: 'members'}
        ]
    });
    Code:
    Ext.define('sfe.model.BalancerMember', {
        extend: 'Ext.data.Model',
        fields: [
            {name: 'gw', type: 'string'},
            {name: 'score', type: 'int'}
        ], belongsTo: 'sfe.model.Balancer'
    });
    and this is my store

    Code:
    Ext.define('sfe.store.Balancers', {
        extend: 'Ext.data.Store',
        model: 'sfe.model.Balancer',
        autoLoad: false,
        proxy: {
            type: 'ajax',
            api: {
                create: 'resources/php/balancers.php?a=create',
                destroy: 'resources/php/balancers.php?a=delete',
                read: 'resources/php/balancers.php',
                update: 'resources/php/balancers.php?a=update'
            },
            reader: {
                type: 'json',
                totalProperty: 'total',
                root: 'balancers'
            }
        }
    });
    on my first grid im able to display both balancers (i can see test and bal2), then on my second grid, on grid one click, for example on "test" i want to see and edit the members for this balancer.
    im not able even to display members.

    this is the grid that i have not info at all displayed

    Code:
    Ext.define('sfe.view.BalancerMembers',{
       extend: 'Ext.panel.Panel',
        title: 'GW por balanceador',
        border: 0,
        alias: 'widget.BalancerMembers',
        layout: 'fit',
        closable: true,
        initComponent: function()
        {
            this.title = 'GW por balanceador '+this.cname;
            var myStore = Ext.StoreManager.lookup("Balancers");
            
            myStore.load(
                    {
                        callback: function()
                        {
                            var balancers = myStore.getAt(1);
                            console.log(balancers);
                            console.log(balancers.get('name'));
                            console.log(balancers.members().getAt(0).get('gw'));
    //                        //iterate over the Orders for each User
    //                        balancers.members().each(function(member) {
    //                            console.log(member.raw.gw);
    //                        });
    
    
                        }
                    });
            
            this.items = [
                {
                    xtype: 'gridpanel',
                    border: 0,
                    store: myStore,
                    tbar: [
                        {
                            xtype: 'button',
                            text: 'Aplicar cambios',
                            icon: 'resources/images/check.png',
                            handler: function(grid, rowIndex, colIndex) {
                                myStore.sync();
                            }
                        },
                        {
                            xtype: 'button',
                            text: 'Refrescar',
                            icon: 'resources/images/play.png',
                            handler: function()
                            {
                                myStore.load();
                            }
                        }
                    ],
                    columns: [
                        {text: 'gw', dataIndex: 'members.gw'},
                        {text: 'score', dataIndex: 'members.score'}
                    ],
                    plugins: [{ptype: 'cellediting', clicksToEdit: 1}]
                }
            ];
            this.callParent(arguments);
        }
    });

  2. Check the below example, Hope this may help you.

    http://jsfiddle.net/alexrom7/rF8mt/2/

  3. #2
    Sencha User
    Join Date
    Mar 2011
    Location
    Hyderabad
    Posts
    106
    Answers
    10

    Default

    Check the below example, Hope this may help you.

    http://jsfiddle.net/alexrom7/rF8mt/2/

  4. #3
    Sencha User
    Join Date
    May 2010
    Posts
    14
    Answers
    1

    Default

    Thanks, perfect.

  5. #4
    Sencha User
    Join Date
    May 2010
    Posts
    14
    Answers
    1

    Default

    sorry, what's the proper way to update this data?

Tags for this Thread

Posting Permissions

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