🐛 Fix issue #3236
This commit is contained in:
parent
56c7cc0efc
commit
0985c87b69
1 changed files with 9 additions and 8 deletions
|
@ -81,18 +81,19 @@
|
||||||
methods: {
|
methods: {
|
||||||
compileFlatState () { // so we have always a relation parent/children of each node
|
compileFlatState () { // so we have always a relation parent/children of each node
|
||||||
let keyCounter = 0;
|
let keyCounter = 0;
|
||||||
|
let childrenKey = this.childrenKey;
|
||||||
const flatTree = [];
|
const flatTree = [];
|
||||||
function flattenChildren(node, parent) {
|
function flattenChildren(node, parent) {
|
||||||
node.nodeKey = keyCounter++;
|
node.nodeKey = keyCounter++;
|
||||||
flatTree[node.nodeKey] = { node: node, nodeKey: node.nodeKey };
|
flatTree[node.nodeKey] = { node: node, nodeKey: node.nodeKey };
|
||||||
if (typeof parent != 'undefined') {
|
if (typeof parent != 'undefined') {
|
||||||
flatTree[node.nodeKey].parent = parent.nodeKey;
|
flatTree[node.nodeKey].parent = parent.nodeKey;
|
||||||
flatTree[parent.nodeKey].children.push(node.nodeKey);
|
flatTree[parent.nodeKey][childrenKey].push(node.nodeKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.children) {
|
if (node[childrenKey]) {
|
||||||
flatTree[node.nodeKey].children = [];
|
flatTree[node.nodeKey][childrenKey] = [];
|
||||||
node.children.forEach(child => flattenChildren(child, node));
|
node[childrenKey].forEach(child => flattenChildren(child, node));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.stateTree.forEach(rootNode => {
|
this.stateTree.forEach(rootNode => {
|
||||||
|
@ -109,11 +110,11 @@
|
||||||
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.children.every(node => node.checked));
|
this.$set(parent, 'checked', parent[this.childrenKey].every(node => node.checked));
|
||||||
this.$set(parent, 'indeterminate', !parent.checked);
|
this.$set(parent, 'indeterminate', !parent.checked);
|
||||||
} else {
|
} else {
|
||||||
this.$set(parent, 'checked', false);
|
this.$set(parent, 'checked', false);
|
||||||
this.$set(parent, 'indeterminate', parent.children.some(node => node.checked || node.indeterminate));
|
this.$set(parent, 'indeterminate', parent[this.childrenKey].some(node => node.checked || node.indeterminate));
|
||||||
}
|
}
|
||||||
this.updateTreeUp(parentKey);
|
this.updateTreeUp(parentKey);
|
||||||
},
|
},
|
||||||
|
@ -144,8 +145,8 @@
|
||||||
for (let key in changes) {
|
for (let key in changes) {
|
||||||
this.$set(node, key, changes[key]);
|
this.$set(node, key, changes[key]);
|
||||||
}
|
}
|
||||||
if (node.children) {
|
if (node[this.childrenKey]) {
|
||||||
node.children.forEach(child => {
|
node[this.childrenKey].forEach(child => {
|
||||||
this.updateTreeDown(child, changes);
|
this.updateTreeDown(child, changes);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue