Last active
August 1, 2017 14:54
-
-
Save ZackFox/71014f96c2c9e1785eb9e9a7983fb968 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeTree(list, node) { | |
const tree = []; | |
list.forEach((item) => { | |
if (item.parent_id !== null) { | |
if(list[item.parent_id-1]["children"] === undefined){ | |
list[item.parent_id-1].children = []; | |
} | |
list[item.parent_id-1].children.push(item); | |
} else { | |
tree.push(item); | |
} | |
}); | |
console.log(tree); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment