Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 139833

How to give JSON Object an ID with depth first search Angular 8?

$
0
0

In my current project I need to display a JSON file in a tree (angular2-tree-component). For the tree to recognize the JSON objects, each object needs an ID. I want to add the ID with Depth first search.

But currently I have no idea how to implement this.

My JSON structure:

var test = [{ 
  object: 
    [{
      name2: "name2",
      name3: "name3",
      object: [{
        name4: "name4",
        name5: "name5",
        object: [{
          name6: "name6",
        }]
      }]
    }]
}]

Accepted output:

nodes = [
    {
      id: 1,
      name: 'root1',
      children: [
        { id: 2, name: 'child1' }
      ]
    },
    {
      id: 4,
      name: 'root2',
      children: [
        { id: 5, name: 'child2.1' }
      ]
    }
  ];

Viewing all articles
Browse latest Browse all 139833

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>