递归对tree求和每一层节点数量
2022-01-02 本文已影响0人
jesse28
![](https://img.haomeiwen.com/i12429965/ee7abb9a1f79c35e.png)
对这类解构的数据进行求和
//递归对数节点求和
countSum(arr){
for(let i=0; i<arr.length; i++) {
if(arr[i] && arr[i].children) {
this.sum += arr[i].children.length
this.countSum(arr[i].children);
}
}
},