PDA

View Full Version : Mapping of fields in Model with set of array data



abhigudi
20 May 2013, 9:36 AM
Hi

I have Json data in the format for example

{
data:[{
"XYZ":"data",
"Items":[{"id":"1","Name":"abc"},
{"id":"2","Name":"def"}
]
}]
}
so now when doing the mapping in Model

{ name : 'Name', mapping : 'items.name' }

But i am not getting any results,Can anyone help me how do we do mapping for set of array data in Model.

Thanks
AbhiGudi

slemmon
22 May 2013, 9:05 AM
For that mapping to work you'd want "Name" to be a direct member of Items -vs- be a root member in an object in an array under Items.

Here's an example:


Ext.create('Ext.data.Store', {
storeId:'simpsonsStore',
fields:['name', 'email', {
name: 'phone',
mapping: 'phone.number'
}],
data:{'items':[
{ 'name': 'Lisa', "email":"lisa@simpsons.com", "phone": {"number": "321-555-1212"} }
]},
proxy: {
type: 'memory',
reader: {
type: 'json',
root: 'items'
}
}
});


Ext.create('Ext.grid.Panel', {
title: 'Simpsons',
store: Ext.data.StoreManager.lookup('simpsonsStore'),
columns: [
{ text: 'Name', dataIndex: 'name' },
{ text: 'Email', dataIndex: 'email', flex: 1 },
{ text: 'Phone', dataIndex: 'phone' }
],
height: 200,
width: 400,
renderTo: Ext.getBody()
});