1

I use angular 7. my query return a json data which has this 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": []
    }
]

I want to loop this data and essentially loop the children data.

and I want to make some test.

I try with this code which has problem to loop 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 didn't find the way to loop the children data .

Any help would be greatly appreciated

1 Answer 1

0

Should be something like:

const objects = Object.keys(data).map(key => data[key]);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.