接口里获取的数据
在接口数据里添加一个属性lable lable的值和接口数据中deptName值是一样的
getDeptList().then((res:any)=>{
let map = new Map();
res.forEach((item:any)=>{
map.set(item.label,item.deptName);
item.label = map.has(item.label) ? map.get(item.label) : 0;
item.children.forEach((item2:any)=>{
map.set(item2.label,item2.deptName);
item2.label = map.has(item2.label) ? map.get(item2.label) : 0;
item2.children.forEach((item3:any)=>{
map.set(item3.label,item3.deptName);
item3.label = map.has(item3.lable) ? map.get(item3.label) : 0;
})
})
})
options.value = res
})
这是数据里就会添加一个lable map只能用添加一个属性 如果我们要添加多个属性就需要一下写法
getDeptList().then((res:any)=>{
console.log(res)
res.forEach((item:any)=>{
res.forEach((item:any)=>{
item.label = item.deptName
item.value = item.deptId
item.children.forEach((item2:any,i:number,arr)=>{
item2.label = item2.deptName
item2.value = item2.deptId
item2.children.forEach((item3:any,i:number,arr)=>{
item3.label = item3.deptName
item3.value = item3.deptId
})
})
})
})
options.value = res
console.log(res)
})