In my application, I create a JavaScript object based on a JSON response from a server like this:
{ name: "root", id: 1, children: [ { name: "child one", id: 11, children: [ {name: "grand child 1", id: 111, children: []}, {name: "grand child 2", id: 112, children: []} ] }, { name: "child two", id: 12, children: [] } ] }
I create a new node, for example:
{name: "grandchild three", id: 113, children:[]}
With that in mind, how can I add a new grandson to its parent element with id 11? Please note that I do not know the static path to the node with id == 11 , so I wonder how I could get this node just knowing its id .
Edit: note that the identifier in the real case DOES NOT encode the path to the objects. I created this simple example to demonstrate the data structure I'm dealing with. But I can not get the path to the object using its id in my real application.
source share