获得徽章 14
- export const nestedToFlat: (arr: any[], pId?: number | string, pKey?: string, childKey?: any) => any[] = (arr, pId = 0, pKey = "id", childKey = "children") => {
return [].concat(...arr.map(item => {
const temp = JSON.parse(JSON.stringify(item[childKey]))
delete item[childKey]
return [].concat({ ...item, pId }, ...nestedToFlat(temp, item[pKey], pKey, childKey))
}))
}展开评论点赞
![[比心]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_113.582f64b.png)
![[抠鼻]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_39.5b41924.png)
![[流泪]](http://lf-web-assets.juejin.cn/obj/juejin-web/xitu_juejin_web/img/jj_emoji_6.dde0d83.png)