adamjkb/bark

Return children recursively in nested array.

Opened this issue · 2 comments

I have a model named Page which can have multiple children, which in return can have its own children (and so on).
I would like to have a functiion like findChildren that would return (given a node/parent) children and its grandchildren in a nested array.

For example:

{
  name: 'parent',
  children: [
    {
      name: 'child1',
    },
    {
      name: 'child2',
      children: [
        {
          name: 'grandchild1',
          children: [*so on*],
        }
      }
    ]
}

findDescendants is the function that will give you the result you are looking for but in a flat array.

That said I like the idea of creating a nested array from a flat array. I imagine it as a utility function that take the result of any function call and format it into a nested array tree.

Hi @adamjkb , is there an ETA for this one? it's like a mandatory thing for me