react-arborist icon indicating copy to clipboard operation
react-arborist copied to clipboard

Is it possible to have different childrenAccessor?

Open FloorianB opened this issue 1 year ago • 1 comments

I have a data object with different children elements. Is it possible to have different childrenAccessor?

example: level 2 => children_name_entries, level 3 => children_another_name_entries

export const data = [
  { id: "1", name: "Random" },
  { id: "2", name: "Random" },
  {
    id: "3",
    name: "Random",
    children_name_entries: [
      { id: "1", name: "Random" },
      { id: "2", name: "Random" },
      { id: "3", name: "Random",  children_another_name_entries: [
      { id: "1", name: "Random" },
      { id: "2", name: "Random" },
      { id: "3", name: "Random" }
    ] }
];

Thanks a lot :)

FloorianB avatar Jan 13 '23 13:01 FloorianB

Maybe, you can pass a function to the childrenAccessor prop. That function gives you the node from your data. If you can figure out which level your node is, you can return props with different children.

jameskerr avatar Jan 13 '23 17:01 jameskerr