I have a tree structure as follows which is rendered using jsTree:
Root
Child 1
Child 1 - 1
Child 2 - 2
Child 2
Root2
Child 1
The tree is created dynamically by the user from the UI using a form and button clicks for adding nodes and attributes for each node. These attributes are collected using a form when the user clicks on a particular node. I am storing the node information in a list with node name and it's parent as follows:
<ul>
<li data-node="Root 1" data-parent = ''>[Form to add attributes]</li>
<li data-node="Child 1" data-parent="Root 1">[Form to add attributes]</li>
<li data-node="Child 2" data-parent="Root 1">[Form to add attributes]</li>
... and so on.
I need to collect that data, in the following JSON format:
Root1: {
formdata: {...}
children: {
Child 1: {
formdata: {...}
children: {
Child 1 - 1: {
formdata: {...}
}
Child 1 - 2: {
formdata: {...}
}
}
}
Child 2: {
formdata: {...}
children: {
Child 1 - 1: {
formdata: {...}
}
}
}
}
}
... and so on.
It could be N levels deep. I am only able to visualise collection going down one branch. If I dig into Root 1 > Child 1 > Child 1 - 1, I am not able to figure out how to come back to the parent, while maintaining the collected data.
Any help would be appreciated.