js将树形结构的数组扁平化(按顺序)
时间 2020-06-29
标签
js
将
树
形
结构
数组
扁平
化
按
顺序
var newArr = []新建一个数据,用于存储扁平化化后的数组
flatData(arr) {
arr.forEach(item => {
this.res.push(item)
item.children && item.children.length > 0 ? this.flatData(item.children) : ""
item.children = '' //若是扁平化后的数组须要显示父子层级,能够把这一项删除
})
}