This commit is contained in:
mo.duan 2019-10-09 16:41:00 +08:00
parent a6068736cb
commit b93725bbb9
2 changed files with 51 additions and 71 deletions

View file

@ -1,81 +1,55 @@
<template> <template>
<Tree :data="data3" :load-data="loadData" show-checkbox></Tree> <div>
<Tree ref="treeRef" :data="data4" show-checkbox multiple></Tree>
<Button @click="get">
get
</Button>
</div>
</template> </template>
<script> <script>
//bug #6139
export default { export default {
data () { data () {
return { return {
data3: [ data4: [
{ {
title: 'parent', title: 'parent 1',
loading: false, expand: true,
children: [] children: [
{
title: 'parent 1-1',
expand: true,
children: [
{
title: 'leaf 1-1-1',
checked : false,
disabled: true
},
{
title: 'leaf 1-1-2'
}
]
},
{
title: 'parent 1-2',
expand: true,
children: [
{
title: 'leaf 1-2-1',
},
{
title: 'leaf 1-2-1'
}
]
}
]
} }
] ]
}; }
}, },
methods: { methods: {
loadData (item, callback) { get(){
setTimeout(() => { console.log(this.$refs.treeRef.getCheckedNodes())
const isSet = Math.ceil(Math.random()*10)%2;
let data = [];
if( isSet ){
data = [
{
title: 'children-1',
loading: false,
children: []
}
];
}
callback(data);
}, 1000);
} }
} }
}; }
</script> </script>
<!--<template>-->
<!-- <Tree :data="data2" check-directly show-checkbox></Tree>-->
<!--</template>-->
<!--<script>-->
<!-- export default {-->
<!-- data () {-->
<!-- return {-->
<!-- data2: [-->
<!-- {-->
<!-- 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'-->
<!-- }-->
<!-- ]-->
<!-- }-->
<!-- ]-->
<!-- }-->
<!-- ]-->
<!-- }-->
<!-- }-->
<!-- }-->
<!--</script>-->

View file

@ -121,9 +121,9 @@
const node = this.flatState[nodeKey].node; const node = this.flatState[nodeKey].node;
const parent = this.flatState[parentKey].node; const parent = this.flatState[parentKey].node;
if (node.checked == parent.checked && node.indeterminate == parent.indeterminate) return; // no need to update upwards if (node.checked == parent.checked && node.indeterminate == parent.indeterminate) return; // no need to update upwards
if (node.checked == true) { if (node.checked == true) {
this.$set(parent, 'checked', parent[this.childrenKey].every(node => node.checked)); // #6121
this.$set(parent, 'checked', parent[this.childrenKey].every(node => node.checked || node.disabled !== undefined ));
this.$set(parent, 'indeterminate', !parent.checked); this.$set(parent, 'indeterminate', !parent.checked);
} else { } else {
this.$set(parent, 'checked', false); this.$set(parent, 'checked', false);
@ -160,10 +160,16 @@
}, },
updateTreeDown(node, changes = {}) { updateTreeDown(node, changes = {}) {
if (this.checkStrictly) return; if (this.checkStrictly) return;
for (let key in changes) { for (let key in changes) {
this.$set(node, key, changes[key]); // after #6121
if( key === 'checked' && node.disabled ){
this.$set(node, key, node.checked);
}else{
this.$set(node, key, changes[key]);
}
// before -- this.$set(node, key, changes[key]);
} }
if (node[this.childrenKey]) { if (node[this.childrenKey]) {
node[this.childrenKey].forEach(child => { node[this.childrenKey].forEach(child => {
this.updateTreeDown(child, changes); this.updateTreeDown(child, changes);