antd vue Tree组件,通过key递归获取该节点信息
<template><div class="tzgl_wrap"><a-tree:tree-data="treeData"@select="treeSelect"default-expand-all><template slot="title" slot-scope="{ title }"><span
·
<template>
<div class="tzgl_wrap">
<a-tree
:tree-data="treeData"
@select="treeSelect"
default-expand-all
>
<template slot="title" slot-scope="{ title }">
<span>{{ title }}</span>
</template>
</a-tree>
</div>
</template>
<script>
import {
MainPageTree
} from '@/api/dwActivityManage'
export default {
components: {
Book
},
data() {
return {
treeData: [],
treeInfo: {},
}
},
mounted() {
this.getTreeData()
},
methods: {
getTreeData() {
MainPageTree().then(res => {
if (res.code == 200) {
this.treeData = res.data
// this.generateList(res.data)
}
})
},
treeSelect(e) {
this.recursiveFilter(this.treeData, e[0])
console.log(this.treeInfo,'======treeInfo')
},
// 通过key 获取树节点信息
recursiveFilter(tree, keys) {
let data = tree.filter(item => item.key == keys)
if (data.length != 0) {
this.treeInfo = data[0]
} else {
tree.map(item => {
if (item.children) {
//递归循环
this.recursiveFilter(item.children, keys)
}
})
}
return data
},
}
}
</script>
打印结果:
更多推荐
已为社区贡献13条内容
所有评论(0)