Last active
May 29, 2020 15:20
-
-
Save giorgiberia/4be7bd89c533b56853846e3596511605 to your computer and use it in GitHub Desktop.
parent child task sub tasks flat array to nested by children
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
def buildTree(tasks, parentId=0): | |
branch = [] | |
for task in tasks: | |
if task['parent_id'] == parentId: | |
children = buildTree(tasks, task['id']) | |
if children: | |
# print(list(children.keys())) | |
task['children'] = children | |
else: | |
task['children'] = [] | |
task['text'] = task['name'] | |
branch.append(task) | |
return branch |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
produces nested array of parent child objects