🐛 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: {
|
||||
compileFlatState () { // so we have always a relation parent/children of each node
|
||||
let keyCounter = 0;
|
||||
let childrenKey = this.childrenKey;
|
||||
const flatTree = [];
|
||||
function flattenChildren(node, parent) {
|
||||
node.nodeKey = keyCounter++;
|
||||
flatTree[node.nodeKey] = { node: node, nodeKey: node.nodeKey };
|
||||
if (typeof parent != 'undefined') {
|
||||
flatTree[node.nodeKey].parent = parent.nodeKey;
|
||||
flatTree[parent.nodeKey].children.push(node.nodeKey);
|
||||
flatTree[parent.nodeKey][childrenKey].push(node.nodeKey);
|
||||
}
|
||||
|
||||
if (node.children) {
|
||||
flatTree[node.nodeKey].children = [];
|
||||
node.children.forEach(child => flattenChildren(child, node));
|
||||
if (node[childrenKey]) {
|
||||
flatTree[node.nodeKey][childrenKey] = [];
|
||||
node[childrenKey].forEach(child => flattenChildren(child, node));
|
||||
}
|
||||
}
|
||||
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 == 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);
|
||||
} else {
|
||||
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);
|
||||
},
|
||||
|
@ -144,8 +145,8 @@
|
|||
for (let key in changes) {
|
||||
this.$set(node, key, changes[key]);
|
||||
}
|
||||
if (node.children) {
|
||||
node.children.forEach(child => {
|
||||
if (node[this.childrenKey]) {
|
||||
node[this.childrenKey].forEach(child => {
|
||||
this.updateTreeDown(child, changes);
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue