I am currently utilizing Angular 7 and have a query that returns JSON data with a specific format:
[
{
"text": "test 1",
"value": "1",
"nbr": "1",
"children": [
{
"text": "test 1_1",
"value": "1_1",
"nbr": "2",
"children": [
{
"text": "test 1_1_1",
"value": "1_1_1",
"nbr": "1",
"children": []
},
{
"text": "test 1_1_2"",
"value": "1_1_2",
"nbr": "0",
"children": []
},
{
"text": "test 1_1_3"",
"value": "1_1_3",
"nbr": "0",
"children": []
}
]
},
{
"text": "test 1_2",
"value": "1_2",
"nbr": "0",
"children": []
}
]
},
{
"text": "test 2",
"value": "2",
"nbr": "0",
"children": []
}
]
My goal is to iterate through this data and specifically loop through the children data.
Additionally, I need to perform some tests along the way.
Here is the code snippet I've tried so far, but I'm facing an issue looping through the children data:
this.httpservice.query({
}).subscribe((res: HttpResponse<TestEntity[]>) => {
this.temp= res.body;
this.temp.forEach((x) => {
x["children"].forEach(x => {
if(x.nbr=='0')
{
// test code
}
x["children"].forEach(x => {
if(x.nbr=='0')
{
// test code
}
})
})
});
});
I'm struggling to find a way to efficiently loop through the children data in this scenario.
Any assistance or guidance would be highly appreciated.