Construct hierarchy tree from flat list with parent field?
问题 I have a list of "page" objects with a parent field. This parent field references another object in the list. I would like to create a tree hierarchy from this list based on this field. Here is what my original list looks like: [ { id: 1, title: 'home', parent: null }, { id: 2, title: 'about', parent: null }, { id: 3, title: 'team', parent: 2 }, { id: 4, title: 'company', parent: 2 } ] I would like to convert it into a tree structure like this: [ { id: 1, title: 'home', parent: null }, { id: