PDA

View Full Version : hasMany on nested JSON



siggi
9 Jan 2013, 2:59 AM
Hello,

I'm trying to populate a store with nested JSON on Ext JS 4.1.3.

the JSON is like:


{ "chartdata":{
"chartdatatype":[{
"type":"BUCHUNG",
"chartdataentry":[{
"timeframe":"2012-02",
"revenuesum":676,
"bookings":1,
"passengersum":2,
"provisionsum":0,
"revenuesumprev":1142,
"bookingsprev":1,
"passengersumprev":2,
"provisionsumprev":0
},{
"timeframe":"2012-10",
"revenuesumprev":2308,
"bookingsprev":1,
"passengersumprev":4,
"provisionsumprev":0
},{
"timeframe":"2012-09",
"revenuesumprev":4288,
"bookingsprev":3,
"passengersumprev":7,
"provisionsumprev":0
},{
"timeframe":"2012-08",
"revenuesumprev":6119,
"bookingsprev":6,
"passengersumprev":17,
"provisionsumprev":0
},{
"timeframe":"2012-07",
"revenuesumprev":4084,
"bookingsprev":4,
"passengersumprev":8,
"provisionsumprev":0
},{
"timeframe":"2012-06",
"revenuesumprev":4620,
"bookingsprev":4,
"passengersumprev":8,
"provisionsumprev":0
},{
"timeframe":"2012-05",
"revenuesumprev":4228,
"bookingsprev":5,
"passengersumprev":10,
"provisionsumprev":0
},{
"timeframe":"2012-04",
"revenuesumprev":1650,
"bookingsprev":2,
"passengersumprev":6,
"provisionsumprev":0
},{
"timeframe":"2012-03",
"revenuesumprev":384,
"bookingsprev":1,
"passengersumprev":2,
"provisionsumprev":0
}]
},{
"type":"STORNO",
"chartdataentry":{
"timeframe":"2012-07",
"revenuesumprev":0,
"bookingsprev":1,
"passengersumprev":0,
"provisionsumprev":0
}
}],
"results":10
}
}

Then I got two models,

AgChartData


Ext.define('Sunny.model.AgChartData',{ extend: 'Ext.data.Model',
root:'chartdata.chartdatatype',
fields: [
{
type:'string',
name:'Type',
mapping:'type',
dateFormat:'Y-m'
}
],
hasMany:{
model:'Sunny.model.AgChartDataEntry',name:'entries'
}
});




and

AgChartDataEntry


Ext.define('Sunny.model.AgChartDataEntry',{ extend: 'Ext.data.Model',
belongsTo:'Sunny.model.AgChartData',
//root:'chartdata.chartdatatype.chartdataentry',
fields: [
{
type:'string',
name:'TimeFrame',
mapping:'chartdataentry.timeframe',
dateFormat:'Y-m'
}
]
});


The Store contains the "Type" elements,but not the "TimeFrame" elements.

What am I doing wrong?

Thank you in advance for your help.

Jad
9 Jan 2013, 4:45 AM
Try this



Ext.define('Sunny.model.AgChartData',{ extend: 'Ext.data.Model', root:'chartdata.chartdatatype', fields: [ { type:'string', name:'Type', mapping:'type', dateFormat:'Y-m' } ], hasMany:{ model:'Sunny.model.AgChartDataEntry',name:'entries', associationKey:'chartdataentry'
}});

siggi
9 Jan 2013, 5:12 AM
works perfectly!

Thank you very much.