PDA

View Full Version : How to use the JsonReader to read the complex Json file in sencha?



bluefox617
18 Apr 2011, 10:08 AM
I know this may be a silly question but I really need your help.

here is callback json file


{
"status": "OK",
"routes": [ {
"summary": "I-40 W",
"legs": [ {
"steps": [ {
"travel_mode": "DRIVING",
"start_location": {
"lat": 41.8781100,
"lng": -87.6297900
},
"end_location": {
"lat": 41.8757000,
"lng": -87.6296900
},
"polyline": {
"points": "eir~FdezuO`NS",
"levels": "BB"
},
"duration": {
"value": 34,
"text": "1 mins"
},
"distance": {
"value": 269,
"text": "0.2 km"
}
},
.....
]}

and I need some of these fields in my app,like routes.legs[i].start_location.lat.....

but I don't know how to get it and how to set my model or set tpl in view.

please hlep me ~~~


Ext.regModel("GdirctionModel", {
fields: [
{name: "start_lat", type: "string"},
{name: "start_lng", type: "string"},
.......
],
proxy: {
type: 'ajax',
url : 'geotest.json',
reader: {
type: 'json',
root: 'legs'
}
}
});

tomalex0
18 Apr 2011, 10:40 PM
specify routes as root

try like this in tpl


var tpl = new Ext.XTemplate(
'<p>Summary: {summary}</p>',
'<p>Legs: ',
'<tpl for="legs">',
'<p>Steps: ',
'<tpl for="steps">',
'<p>{travel_mode}</p>',
'<p>{start_location.lat}</p>',
'</tpl></p>'
'</tpl></p>'
);

I have not tried it, but it should work?