Answer the question
In order to leave comments, you need to log in
How is it optimized to convert a flat structure to a tree structure in JS?
An array with objects is transmitted from the server, it looks something like this:
[
{
id: 1,
path: [2,3]
},
{
id: 2,
path: []
},
{
id: 3,
path: [2]
}
]
[
{
id: 2,
children: [{
id: 3,
children: [
{id: 1},
{id: 4}
]
}]
}
]
Answer the question
In order to leave comments, you need to log in
codepen.io/anon/pen/mOxBeQ?editors=1012
Made based on the mutability of objects in JS, for each item I read only the last element from the path
in IE will not work because Object.assign, if critical, you can replace it with what -something similar
PS: children is not declined, it's already plural)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question