js將樹形結構的數組扁平化(按順序)

  var newArr =  []新建一個數據,用於存儲扁平化化後的數組
 flatData(arr) {
        arr.forEach(item => {
            this.res.push(item)
            item.children && item.children.length > 0 ? this.flatData(item.children) : ""   
            item.children = ''    //若是扁平化後的數組須要顯示父子層級,能夠把這一項刪除
        })
    }
相關文章
相關標籤/搜索