treeConvertToArr(tree) {
let arrs = [];
let result = [];
arrs = arrs.concat(tree);
while (arrs.length) {
let first = arrs.shift(); // 弹出第一个元素
if (first.children) {
//如果有children
arrs = arrs.concat(first.children);
delete first["children"];
}
result.push(first);
}
return result;
},
WeChate2d96059c0f6ecd59564079649d15b80.png
this. treeConvertToArr(result.data)
console.log(this. treeConvertToArr(result.data))//得到[{id:"1",deptName:"长安福特"},{d:"2",deptName:"福特一厂"},{d:"3",deptName:"福特二厂"},{d:"4",deptName:"福特三厂"}]
网友评论