data=[
{"cat_id":3,"name":"沙河","parent_id":1},
{"cat_id":4,"name":"sb镇","parent_id":3},
{"cat_id": 1, "name": "北京", "parent_id": 0},
{"cat_id":5,"name":"昌平","parent_id":1},
{"cat_id":6,"name":"青浦","parent_id":2},
{"cat_id": 2, "name": "上海", "parent_id": 0},
]
def get_tree(data):
lists=[]
tree={}
for item in data:
tree[item['cat_id']]=item
for i in data:
if not i['parent_id']:
lists.append(tree[i['cat_id']])
else:
parent_id=i['parent_id']
if "children" not in tree[parent_id]:
tree[parent_id]["children"]=[]
tree[parent_id]['children'].append(tree[i['cat_id&