遍歷樹結構數據數組
watch: { props(nv, ov) { console.log(nv); console.log(nv.inventories[0].tree,'-------------------------tree'); if(nv.inventories.length != 0){ //list爲循環的樹的數據 this.list = this.treeToList(nv.inventories[0].tree).reverse(); }else{ this.list = []; } }, uuid(nv, ov) { // console.log(nv, '-----uuid'); this.idcs = nv; } }, mounted() { }, methods: { toaddSnap() { this.$router.push({ path: "/addSnap", query: { id: this.idcs, } }); }, treeToList(tree) { var queen = []; var out = []; queen = queen.concat(tree); while (queen.length) { var first = queen.shift(); console.log(first.children,'--------first'); if (first.children) { queen = queen.concat(first.children); delete first["children"]; } out.push(first); } return out;//爲循環的樹結構數組 },
contact方法:ui
concat() 方法用於鏈接兩個或多個數組。this
該方法不會改變現有的數組,而僅僅會返回被鏈接數組的一個副本spa
shift方法:code
shift() 方法用於把數組的第一個元素從其中刪除,並返回第一個元素的值。router
語法:arrayObject.shift()對象
children 屬性返回元素的子元素的集合,是一個 HTMLCollection 對象。blog
reverse 顛倒數據排序排序