//别着急慢慢来肯定能做出来的,下面我的思路给你,我用的是typescript
interface entity {
id: number;
title: string;
children?: children[];
}
interface children {
id: number;
title: string;
children?: children[];
}
//定义list接收扁平型数据
let list: any[]=[]
//递归遍历取出每一个children
const returnft = (it: entity) => {
if (it.children && it.children.length) {
it.children.map(res=>returnft(res))
}
//给list赋值
list.push({id:it.id,title:it.title})
}
//数据源
const where = {
id: 1,
title: "父级",
children: [{
id: 2,
title: "子级1",
children: [{
id: 3,
title: "子级2"
}]
}]
}
//调用自己的递归函数
returnft(where)
console.log(list)