PDA

View Full Version : nested JSON



olvap
2 Feb 2010, 2:21 PM
this is my json, i use columns to set the column model and "data" is that, the data. of course.

in the last column, i use mapping. i like to show the "name" of the second object in "data". i read the faq, nested JSON, but i dont know what im doing wrong.
its works if i dont use the {"pronvicia"} part in the data and the fourts column.

{"columns":[{"width":10,"name":"id","mapping":"data.id","header":"ID","search":"equals"},{"width":100,"name":"name","header":"Departamento","search":"like","sortable":true},{"width":100,"name":"provincia_id","header":"Provincia","search":"equals","sortable":true},{"width":100,"name":"name","mapping":"provincia.name","header":"Provincia","search":"equals","sortable":true}],"total":3,
"data":[{"name":"primer dpto","updated_at":"2010-02-02T14:04:04Z","id":1,"provincia_id":null,"created_at":"2010-02-02T14:04:04Z"},{"provincia":{"name":"asdsad","updated_at":"2010-02-02T13:22:33Z","id":1,"created_at":"2010-02-02T13:22:33Z"},
"name":"otro","updated_at":"2010-02-02T14:18:52Z","id":2,"provincia_id":1,"created_at":"2010-02-02T14:18:52Z"},{"provincia":{"name":"asdsad","updated_at":"2010-02-02T13:22:33Z","id":1,"created_at":"2010-02-02T13:22:33Z"},
"name":"asdasd","updated_at":"2010-02-02T20:13:07Z","id":3,"provincia_id":1,"created_at":"2010-02-02T20:13:07Z"}]}

BitPoet
3 Feb 2010, 3:28 AM
Your provincia data needs to be assigned to an attribute of your basic object with the name "provincia", i.e. (newlines added for clarity):


{...
,"data":[
{"name":"primer dpto","updated_at":"2010-02-02T14:04:04Z","id":1,"provincia":
{
"name":"asdsad","updated_at":"...",...
}
},
{"name":"otro",...}
]}

olvap
3 Feb 2010, 4:49 AM
is not what im doing? "data":[ { "name":"primer dpto","updated_at":"2010-02-02T14:04:04Z","id":1... }, { "provincia":{"name":"asdsad","updated_at":"2010-02-02T13:22:33Z","id":1..}, "name":"otro","updated_at":"2010-02-02T14:18:52Z","id":2,"provincia_id":1... }... the firts row dont have a provincias attribute.

BitPoet
3 Feb 2010, 5:36 AM
Sorry, I take everything back, re-reading the JSON your structure is fine.

BitPoet
3 Feb 2010, 6:31 AM
But one thing I just saw: you've got two fields/columns with identical names, does it help if you rename the second one to e.g. "name": "provname"?