DenQ / list-to-tree

Convert list to tree
BSD 3-Clause "New" or "Revised" License
87 stars 30 forks source link

Child key must be bigger than parent key #27

Closed jesusisao closed 3 years ago

jesusisao commented 3 years ago

Problem

When the child's ID is smaller than the parent's ID, the child may not be associated properly. The reason is that there is code that sorts by parent ID, then sorts by ID, and adds to the tree.

example

before

PR

I think you can solve this problem by sorting the list by the depth of the tree.

Here is a suggestion: https://github.com/DenQ/list-to-tree/pull/26

DenQ commented 3 years ago

@jesusisao Hi. I will to look it in near days. Thanks you!

DenQ commented 3 years ago

Thanks! 💯