主代码
const treeToLabel = (data, arr) => {
let result =[]
const childrenTreeToLabel = (data, arr, result) => {
for(let j = 0; j < data.length; j++) {
if (arr[0] == data[j].value) {
result.push(data[j].label)
if (data[j].children && arr.length > 1) {
return childrenTreeToLabel(data[j].children, arr.slice(1), result)
}
break;
}
}
}
childrenTreeToLabel(data,arr,result)
this.form.province = result[0]
this.form.city = result[1]
return result
}
console.log(treeToLabel(this.city, this.place_value),99999);
data为原始列表
attr为获取到的value列表
添加@change,当选取值改变时,调用函数
参考:
https://www.codeleading.com/article/40132360914/