PDA

View Full Version : JSON root



choni
18 Jan 2007, 8:53 PM
I'm trying to load some JSON data to my dataModel, but, the data comes as an array:
[[]...] I mean there's no root object, so what should I specify in the schema for the
DataModel to load properly??

Besides, How do I get an object from the dataModel given its row id???

I tried this>

var o = dataModel.getRow(3); and Firebug says it returns an arrays where the 4th element is the object I'm trying to get. Further analisis shows that the data is store in the "node" object, so>

var o = dataModel.getRow(3).node should have work, but still I return an array, not an object so I can call the attributes, e.g. o.Age

By the way jack, in the documentation for getRow method I guess the Id parameter is missing, is that correct??


Regards, chony

tryanDLS
19 Jan 2007, 8:15 AM
If your JSON data is only an array, it's not valid JSON notation. It should be something like

{Users:[{ user1}, {user2}, etc]}

dm.getRow(3) returns an array of values for the 3rd entry in your data. There are as many entries in this array as there are columns in your schema (maybe plus 1 for an index).

node is not a property of array, it may be one of the entries in the array though, so (dm.getRow(3))[node] might work or (dm.getRow(3))[idx] where idx is index of node in your schema.

Not sure what you mean about the doc - getRow only takes 1 arg - the rowIndex