This is the specific format of data that I am in need of
this.structure=[
{
id: 1,
name: 'root1',
children: [
{ id: 2, name: 'child1' },
{ id: 3, name: 'child2' }
]
},
{
id: 4,
name: 'root2',
children: [
{ id: 5, name: 'child2.1' },
{
id: 6,
name: 'child2.2',
children:[
{id:7, name:'child2.2.1'}
]
}
]
},
];
When defining the data type, I must create a class structured like this
export class NodeStructure {
id: number;
name: string;
children: NodeStructure[];
}
The issue arises when trying to reference NodeStructure
within itself due to the varying depth of children.
How can I recursively utilize the class inside it.
P.S. This project is built using Angular 2.