PDA

View Full Version : Grid and json data with nested object



djudjublondin
12 Aug 2007, 2:03 AM
Dear all,

I am a complete Javascript/ExtJs beginner, here is my issue :

goal and context : I'd like to define a grid that can get nested data object in json file format and I guess that json data would look like this :



{ 'nodes' :
[
{
'node_id' : '1',
'node_type' : 'task',
'node_children' :
[
{
node_id' : '11',
'node_type' : 'task',
'node_children' : ''
},
{
node_id' : '12',
'node_type' : 'task',
'node_children' : ''
}
]


Nested data can be represented as a "node" that contain similar object in its children property.
Note that the children node have the same properties as the parent node. Of course all the "node" could be stated at the same level without nesting but the json data less human readable. In terms the nesting could apply on more than tow levels.

My actual code in Extjs is :


var reader = new Ext.data.JsonReader(
{
root: "nodes",
id: "node_id"
},
[
{name: "node_id", type:"int"},
{name: "node_type", type: "string"},
{name: "node_title", type: "string"},
{name: "node_children", type: "nodes"} // ??? Is there a specific type ?
]
);


questions :
_ Is it possible to deal with such a format of data with extjs ?
_ If yes how would it be achievable ?
_ What would happen if children have different properties than the parents ?
_ Would it be possible to ignore children node and to collect data into grid only for a specifies level of the nesting?

thanks in advance for kind help. I hope I made myself clear enough.

Julien