You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the tree when an half-checked node has been clicked its status becomes checked. There is no way to override this behavior and instead set it unchecked. This could be useful when a node has a lot of children that are set checked as parent and the checks trigger a lot of functions. it could cause problems in the code execution.
Anyway for who has to do something like that, here how i achieve the aim:
<el-tree
ref="tree"
node-key="id"
show-checkbox
@check-change="toggleItem"
@check="toggleCheck">
</el-tree>
toggleItem(item, checked) {
if(item.halfChecked && checked) {
this.halfClicked = true;
}
if(item.halfChecked && !checked) {
item.halfChecked = false;
}
// Prevent doing anything if an half has been clicked
if(checked && !this.halfClicked) {
... do something for checked node
}
}
toggleCheck(item, treeStatus) {
treeStatus.halfCheckedNodes.forEach(node => {
node.halfChecked = true;
});
if(item.halfChecked) {
// set half unchecked
this.$refs.tree?.setChecked(item.id, false);
// Set all children unchecked
this.setChildrenNodesChecked(item, false);
item.checked = false;
this.halfClicked = false;
}
},
setChildrenNodesChecked(node, checked) {
let children = getChildrenNodes(node) <-- here you have to implement you own function to get children nodes
children.forEach(node => {
this.$refs.tree?.setChecked(node.id, checked);
})
},
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In the tree when an half-checked node has been clicked its status becomes checked. There is no way to override this behavior and instead set it unchecked. This could be useful when a node has a lot of children that are set checked as parent and the checks trigger a lot of functions. it could cause problems in the code execution.
Anyway for who has to do something like that, here how i achieve the aim:
Beta Was this translation helpful? Give feedback.
All reactions