一、背景
List组装树形Tree
二、实现
点击查看代码
listRolePurifySmalls().then(data => {
const list = data || []
const map = {}
list.forEach(item => {
let smalls = map[item.divisionName]
if (!smalls) {
smalls = []
map[item.divisionName] = smalls
}
smalls.push(item)
})
const keys = Object.keys(map)
this.purifySmalls = keys.map(key => {
return { name: key, children: map[key], id: '' }
})
console.log(this.purifySmalls)
})