0

I'm using the TreeModel js library. It looks like the library supports passing a object that has a structure like...

{
 id: 1,
 children: [{
   id: 2,
   childre: []
 }]
}

However, what if I have a tree structure that is an array like...

[
  {
    id: 1,
    children: [],
  },
  {
    id: 2,
    children: [
      id: 5,
      children []
    ]
  }
]

Does the library not support passing an array? Thoughts on how best to deal with this?

xspydr
  • 3,030
  • 3
  • 31
  • 49

1 Answers1

1

You can create a fake root (id=0) whose children are your array:

{
  id: 0,
  children: [
    {
      id: 1,
      children: [],
    },
    {
      id: 2,
      children: [
        id: 5,
        children []
      ]
    }
  ]
}
jnuno
  • 711
  • 5
  • 8