I have key/parent structured like this :
[Object { parent="0", key="5961"}, Object { parent="5961", key="5960"}, Object { parent="5960", key="5826"}, Object { parent="5826", key="5841"}, Object { parent="5841", key="5915"}]
Root object is parent="0" all other are children and that is solved like this :
$.each (data, function(index,value){
key += "/" + value.key;
});
The problem starts when I have more root objects and need to have first root then all children...second root then all children and so on...This is problematic object :
[Object { parent="0", key="5961"}, Object { parent="0", key="5962"}, Object { parent="5961", key="5960"}, Object { parent="5824", key="2237"}, Object { parent="5962", key="5824"}, Object { parent="5960", key="5826"}, Object { parent="2237", key="5834"}, Object { parent="2237", key="5838"}, Object { parent="5826", key="5841"}, Object { parent="2237", key="5843"}, Object { parent="5865", key="5846"}, Object { parent="5865", key="5862"}, Object { parent="5838", key="5865"}, Object { parent="5843", key="5874"}, Object { parent="5834", key="5894"}, Object { parent="5865", key="5912"}, Object { parent="5841", key="5915"}, Object { parent="5865", key="5935"}]
As you can see two root parent="0". There can be more than two root nodes.
Thanks.