在使用element級聯選擇器時,數據從后端獲取雇盖,但是獲取后的數據最后一層中children為空忿等,所以顯示如上。
?//遞歸清除數組每個元素下的children為空的數組
findEmptychildren(arr) {? ?
? let _that = this? ? ? ?
? ?return arr.map((item) => {? ? ? ? ? ?
? ? ?if (item.children.length > 0) {? ? ? ? ? ? ?
? ? ? ? ?that.findEmptychildren(item.children)? ?//遞歸
} else {
? ? ? ? ? ? delete item.children?// children為空數組時刪除 ? ? ? ? ? ? ? ? ? ?
}? ? ? ? ? ? ? ? ? ?
return item? ? ? ? ? ? ? ?
})? ? ? ? ? ?
},
?this.options22222 = this.findEmptychildren(res.data.data)
傳送門:過濾多維數組中為空的children_vue 多級數組的children判斷是否為空-CSDN博客
親測有用4尥凇C辰帧庵寞!