PDA

View Full Version : Model field mapping for nested json.



xjscrafter
12 Dec 2013, 7:46 PM
Not getting data loaded for the multicastip and multicastport fields. Other column "name" loads fine.

model


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


{"myconfigs":[{ "name":"qqqqxxx", "ring":[ { "multicastip":"10.10.10.10", "multicastport":8080 } ]}]}


grid


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();
}

evant
12 Dec 2013, 8:15 PM
Ring is an array, not an object. So you'd need



ring[0].multicastip

xjscrafter
12 Dec 2013, 8:24 PM
Thanks Evan!

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

evant
12 Dec 2013, 8:43 PM
Well... what do you want to happen? ;)

xjscrafter
12 Dec 2013, 8:57 PM
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.