view中 引用Tree组件,在不刷新的情况下怎么取消选中的状态
<template>
<Tree :data="treeList" show-checkbox></Tree>
<Button @click='emptyOptions(treeList)'>清空选中项</Button>
</template>
<script>
export default {
data () {
return {
treeList: [
{
title: 'parent 1',
expand: true,
children: [
{
title: 'parent 1-1',
expand: true,
children: [
{
title: 'leaf 1-1-1'
},
{
title: 'leaf 1-1-2'
}
]
},
{
title: 'parent 1-2',
expand: true,
children: [
{
title: 'leaf 1-2-1'
},
{
title: 'leaf 1-2-1'
}
]
}
]
}
]
}
},
methods: {
// 清空checked
emptyOptions(data) {
data.map((item) => {
if (item.checked != undefined || item.indeterminate != undefined) {
item.checked = false
item.indeterminate = false
}
if (item.children && item.children.length > 0) {
this.emptyOptions(item.children)
}
})
},
},
}
</script>
网友评论