Python list_to_tree
def list_to_tree(self, data, parent=None):
tree = []
for item in data:
tmp = {
"name": item.name,
"uuid": item.uuid,
"category_type": item.category_type,
"parent_category": item.parent_category,
"parent_category_id": item.parent_category_id,
"children": [],
}
if tmp['parent_category_id'] == parent:
children = self.list_to_tree(data, tmp['uuid'])
if len(children) > 0:
tmp['children'] = children
tree.append(tmp)
return tree
本文来自博客园,作者:vx_guanchaoguo0,转载请注明原文链接:https://www.cnblogs.com/guanchaoguo/p/18045036