当前位置:   article > 正文

python 简单的构造树结构_python xtree

python xtree

展示:

def xtree(data):
    list = []
    dict = {}
    if data:
        for i in data:
            dict[i['id']] = i

        for j in data:
            if j['pid'] == 0:
                list.append(j)
            else:
                if 'son' not in dict[j['pid']]:
                    dict[j['pid']]['son'] = []
                dict[j['pid']]['son'].append(j)
        return list

删除:

async def delpermission(ns):
    db = DBPools()
    async with db.sqlorContext('kboss') as sor:
        if ns:
            ns['del_flg'] = '1'
            await sor.U('permission', ns)
            dictns = {'parentid': ns['id']}
            reacs = await sor.R('permission', dictns)
            for i in reacs:
                await delpermission({'id':i['id']})
            return {'status': True, 'msg': '删除成功'}
    return {'status': False, 'msg': '删除失败'}
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/169525
推荐阅读
相关标签
  

闽ICP备14008679号