需求:点击每一级会得到一个id,希望通过id去查到对应的名字
getTreeName(list, id) {
for (let i = 0; i < list.length; i++) {
const a = list[i]
if (a.id === id) {
return a.label
} else {
if (a.children && a.children.length > 0) {
const res = this.getTreeName(a.children, id)
if (res) {
return res
}
}
}
}
},
采用上叙方法可以完成需求
= > 参考博客