Results 1 to 5 of 5

Thread: Model field mapping for nested json.

  1. #1
    Sencha User
    Join Date
    Nov 2013
    Posts
    259
    Answers
    4

    Default Model field mapping for nested json.

    Not getting data loaded for the multicastip and multicastport fields. Other column "name" loads fine.

    model

    Code:
    Ext.define('com.myco.model.MyModel',{
        extend: 'Ext.data.Model',
        fields: [{
            	name: 'name',
            	type: 'string'
            },{
                name: 'multicastip',
                mapping: 'ring.multicastip',
                type: 'auto'
            },
            {
                name: 'multicastport',
                mapping: 'ring.multicastport',
                type: 'auto'
            },
            'objid'
        ],
        idProperty: 'objid'
    });
    data
    Code:
    {"myconfigs":[{    "name":"qqqqxxx",    "ring":[        {            "multicastip":"10.10.10.10",            "multicastport":8080        }    ]}]}
    grid

    Code:
    xtype : 'gridpanel',
    region : 'center',
    itemId : 'myGrid',
    store : new Ext.data.Store({
    	model: 'com.myco.model.MyModel',
    	proxy: {
    		type: 'ajax',
    		reader: {
    			type: 'json',
    			root: 'myconfigs'
    		}
    	}
    }),
    columns : [
    	{
    		xtype : 'gridcolumn',
    		flex : 1,
    		dataIndex : 'name',
    		text : 'Name'
    	},
    	{
    		xtype : 'gridcolumn',
    		dataIndex : 'multicastip',
    		text : 'Multi Cast IP',
    		flex : 1
    	},
    	{
    		xtype : 'gridcolumn',
    		dataIndex : 'multicastport',
    		text : 'Multi Cast Port',
    		flex : 1
    	} ]
    } ]
    loading data in controller on grid render (can't have autoLoad true)

    render: function(comp) {
    var store = comp.getStore();
    var proxy = store.getProxy();
    proxy.url = '/mypath/mypathtwo';
    store.load();
    }

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

    Default

    Ring is an array, not an object. So you'd need

    Code:
    ring[0].multicastip
    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
    Nov 2013
    Posts
    259
    Answers
    4

    Default

    Thanks Evan!

    One more question. What if ring contains more than one item?

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

    Default

    Well... what do you want to happen?
    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.

  5. #5
    Sencha User
    Join Date
    Nov 2013
    Posts
    259
    Answers
    4

    Default

    That's a good point. I'll have to check if there will ever be multiple items.

    In any case, your solution works great.

    You rock Evan! Thanks so much.

Posting Permissions

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