sequelize递归查询获取树状结构
发布日期:2021-07-25 11:32:15 浏览次数:2 分类:技术文章

本文共 821 字,大约阅读时间需要 2 分钟。

class NeedModule{    constructor(id){        this.id = id;    }    async getNeedsTree(){        let rootNeeds = await Needs.findAll({            where : {                 id : this.id             }        })        rootNeeds = await this.getChildNeeds(rootNeeds);        return rootNeeds;    }    async getChildNeeds(rootNeeds){        let expendPromise = [];        rootNeeds.forEach(item => {            expendPromise.push(Needs.findAll({                where : {                    parentId : item.id                }            }))        })        let child = await Promise.all(expendPromise);        for(let [idx , item] of child.entries()){            if(item.length > 0){                item = await getChildNeeds(item);            }            rootNeeds[idx].child = item;        }        return rootNeeds;    }}

 

转载地址:https://blog.csdn.net/qq_32615575/article/details/118000527 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:dva数据流effects获取返回值的几种方式
下一篇:Mac 查看端口占用情况及杀死进程

发表评论

最新留言

网站不错 人气很旺了 加油
[***.192.178.218]2024年03月27日 22时58分25秒