PDA

View Full Version : Issue with JSON format....or my store?



Jangla
12 Jun 2010, 3:31 PM
I've got this store declaration:




var myStore = new Ext.data.JsonStore({
url : 'url.json',
idProperty : 'id',
totalProperty : 'count',
root : 'ref',
autoLoad : false,
fields: [
{name: 'id', mapping: 'id'},
{name: 'title', mapping: 'title'}
],
// the return will be XML, so lets set up a reader
reader : new Ext.data.JsonReader({
root: 'ref'
})

});


...and this json at the url of the store:



{
"header":[
{
"title":"List of Stuff",
"status":"ok",
"content":[
{
"type":"file",
"data":"list",
"count":"5",
"ref":
[{
"id":"1",
"title":"image 1"
},{
"id":"2",
"title":"image 2"
},{
"id":"3",
"title":"image 3"
},{
"id":"4",
"title":"image 4"
},{
"id":"5",
"title":"image 5"
}
]
}
]
}
]
}
...but I'm having trouble getting the store to read the data. Posisbly something wrong with my field mappings? I've tried loads of things but would appreciate some help. I've seen and followed various posts around but they all deal with the root being higher up the JSON that in my response JSON so I'm struggling to get my head round it a little.

Thanks

evant
12 Jun 2010, 11:17 PM
I don't really know why the response is so complicated, considering each array only has one item... anyway:



root: 'header[0].content[0].ref'

Jangla
13 Jun 2010, 1:51 AM
It's an output format that's standardised across all our json outputs.

Anyway, your solution works! Thanks!