bark icon indicating copy to clipboard operation
bark copied to clipboard

Return children recursively in nested array.

Open ashoktamang opened this issue 2 years ago • 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*],
        }
      }
    ]
}

ashoktamang avatar Sep 09 '23 12:09 ashoktamang

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.

adamjkb avatar Sep 09 '23 15:09 adamjkb

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

Tsimopak avatar Sep 15 '24 18:09 Tsimopak