调用
const id = 'xxx';
const arr = [];
const ids = await this.getChild(id, arr);
递归获取
/**
* 得到子级
*/
async getChild(id: string, arr: any[]) {
const data: any[] = await db.gzwDecisionItem.findMany({
where: {
deletedAt: 0,
pid: id,
},
});
for (const child of data) {
arr.push(child.id);
arr = uniq(arr); /// lodash的数组对象去重
arr = arr.concat(await this.getChild(child.id, arr)); /// lodash的数组合并
}
return arr;
}