I have an object structured like this:
var list = [
{
category:'CATEGORY 1',
label:'Item 1',
children:[{
category:'CATEGORY 2',
label:'Item 1',
children:[]
},{
category:'CATEGORY 2',
label:'Item 2',
children:[{
category:'CATEGORY 3',
label:'Item 1',
children:[]
},{
category:'CATEGORY 3',
label:'Item 2',
children:[]
}]
}]
},
{
category:'CATEGORY 1',
label:'Item 2',
children:[{
category:'CATEGORY 2',
label:'Item 3',
children:[]
},{
category:'CATEGORY 2',
label:'Item 4',
children:[{
category:'CATEGORY 3',
label:'Item 2',
children:[]
},{
category:'CATEGORY 3',
label:'Item 3',
children:[]
}]
}]
}
]
I need to display the object structure in a view.
https://i.sstatic.net/LyPdy.png
The JSON data is nested deep with multiple layers, possibly 6 to 8 children in each node. I am struggling to figure out how to achieve this using JavaScript.
Should I separate each category and iterate through each object individually?