Json Tree Structure:
{
"id": "30080",
"dataelements": {
"Name": "abc"
},
"children": [
{
"id": "33024",
"dataelements": {
"Name": "a"
},
"children": [
{
"id": "33024",
"dataelements": {
"Name": "b"
},
"children": [
{
"id": "33024",
"dataelements": {
"Name": "z"
},
"children": []
}
]
}
]
},
{
"id": "4800",
"dataelements": {
"Name": "d"
},
"children": [
{
"id": "4800",
"dataelements": {
.........................
The given image represents the nested JSON data structure. Each child object in this tree creates a node model, and can contain further nested children.
if (ele == "dataelements")
{
var categoryNode = new NodeModel(
{
label: row.dataelements.Name,
icons: [{ iconName: 'product' }],
grid: row[ele]
});
}
if(ele == "children")
{
var subCategoryNode;
var subCategoryIndex = 1;
for (var i=0,len=row.children.length;i<len;i++)
{
subCategoryNode = new NodeModel(
{
label: row.children[i].dataelements.Name,
icons: [{
iconName: '3dpart'
}],
grid: row.children[i].dataelements
});
categoryNode.addChild(subCategoryNode);
}
}
This code implementation currently handles only one level of child nodes. The challenge is to extend it to dynamically handle multiple levels of nested children without knowing the exact depth beforehand.