PDA

View Full Version : [SOLVED] Nested JSon for FormPanel



rajpatel
6 Oct 2010, 5:47 AM
Hi all.

So i know this has been an issue on the forums before and I have searched and tried out the solutions posted, but I can't seem to get my nested JSON to populate any of my FormPanel fields.

I have the following JSON returned:


{
"data":{
"PDUser":{
"email":"test1",
"userId":"test1",
"firstName":"Raj",
"lastName":"Patel",
"enabled":true,
"locked":false,
"badLoginAttempts":0,
"activated":true,
"mobile":"",
"workPhone":"",
"createTimestamp":1285643850125,
"department":"",
"id":9,
"lastModified":1286322088773,
"description":null,
"password":"7c6a180b36896a0a8c02787eeafb0e4c"
},
"Company":{
"companyTaxCode":"123123",
"email":"test1",
"city":"21321321",
"postalCode":"",
"primaryContact":"Raj Patel",
"mobile":null,
"workPhone":"123",
"branch":"",
"createTimestamp":1286322088773,
"address":"12312",
"name":"1213",
"id":37,
"state":"213",
"type":null,
"country":"312",
"description":null
}
},
"success":true
}

And my JSON Reader:


var reader = new Ext.data.JsonReader({
successProperty: 'success',
root: 'data',
fields: [
{name:'name', type: 'string', mapping:'Company.name'},
{name:'fisrtName', type: 'string', mapping:'PDUser.firstName'}
]
});

My field names in the form are 'name' and 'firstName'.

This isn't working for me.

Any ideas?

Thanks,
Raj

Condor
6 Oct 2010, 5:52 AM
A JsonReader expects the root to be an array. Either fix your data or use:

root: function(v){
return [v.data];
}

rajpatel
6 Oct 2010, 5:23 PM
Awesome thanks!!!

That did it :)