// 树状结构数据扁平化
flagTree(arr) {
//声明一个空的数组
let result = []
//for of 循环
for (item of arr) {
//先深拷贝一层
var res = JSON.parse(JSON.stringify(item))
//删除所有的child
delete res['children']
// 然后给新数组添加
result.push(res)
// 如果当前child为数组并且长度大于0,才可进入flagTree()方法
if (item.children instanceof Array && item.children.length > 0) {
result = result.concat(this.flagTree(item.children))
}
}
return result
},