Attribute check-strictly The official document provides the property check-strictly, which determines whether to strictly follow the practice of not associating parent and child items with each other when a check box is displayed. The default value is false. System character menu control issues The problem is that when controlling the system's character menu, the following conditions must be met: Requirements:1. check-strictly=false does not work According to the conditions that need to be met, it is obvious that check-strictly is set to false, so starting from the basis of the mutual relationship between check-strictly=false and the parent and child, the problem that needs to be solved is: 2. check-strictly=true, try it You can only try to set check-strictly to true, starting from check-strictly=true to strictly follow the principle that the parent and child are not related to each other. The problem that needs to be solved is: Solution code:1. el-tree tag attributes<el-tree ref="tree" :data="treeMenus" :props="multiProps" :show-checkbox="true" node-key="menuId" highlight-current :expand-on-click-node="false" :default-checked-keys="checkedId" :check-strictly="true" @check="clickDeal"> Node-key: The attribute used as a unique identifier for each tree node. The entire tree should be unique. A key value that uniquely identifies a node. According to the backend's response, for :props="multiProps", my configuration is: multiProps: { children: 'childs', label: 'name', disabled: this.isDisabled } The childrens field is identified as the child node and name is the node name. By default, children is identified as the child node and label is the node name. 2. Reassign the multiple-select tree when the el-tree component changesupdated () { // Set the default value for the multiple-select tree this.$refs.tree.setCheckedKeys(this.checkedId) }, checkedId is an array of checked nodes, without distinguishing between parent and child nodes. 3. Special processing when clicking on a check boxclickDeal (currentObj, treeStatus) { // Used for: When the parent and child nodes are strictly unrelated, the parent node notifies the child node to change synchronously when the parent node is checked, thus realizing a one-way association. let selected = treeStatus.checkedKeys.indexOf(currentObj.menuId) // -1 is not selected // selected if (selected !== -1) { // As long as the parent node is selected, the child node is selected this.selectedParent(currentObj) // Unify the processing of child nodes to the same check state this.uniteChildSame(currentObj, true) } else { // Unselected processing: All child nodes are unselected if (currentObj.childs.length !== 0) { this.uniteChildSame(currentObj, false) } } }, // Unify the processing of child nodes with the same check status uniteChildSame (treeList, isSelected) { this.$refs.tree.setChecked(treeList.menuId, isSelected) for (let i = 0; i < treeList.childs.length; i++) { this.uniteChildSame(treeList.childs[i], isSelected) } }, // Unified processing of parent nodes as selected selectedParent (currentObj) { let currentNode = this.$refs.tree.getNode(currentObj) if (currentNode.parent.key !== undefined) { this.$refs.tree.setChecked(currentNode.parent, true) this.selectedParent(currentNode.parent) } }, This is the end of this article about element's el-tree multiple-select tree (checkbox) parent-child node association or non-association. For more related element el-tree multiple-select tree non-association content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to quickly deploy Gitlab using Docker
>>: MySQL Failover Notes: Application-Aware Design Detailed Explanation
Here are two terminal split screen tools: screen ...
This article shares the specific code of jQuery t...
This article mainly explains the style of buttons...
I've been using redis recently and I find it ...
We don't need to elaborate too much on the ad...
This is the style recommendation given by the W3C ...
Table of contents Process Communication Bidirecti...
Steps to configure whitelist access in mysql 1. L...
Web page design related questions, see if you can...
You can use yum to install all dependencies toget...
Table of contents (1) Introduction: (2) The ways ...
Preface The concept of dark mode originated from ...
This article mainly introduces: using Vue to impl...
1. Introduction: I think the changes after mysql8...
This article shares the specific code of Vue recu...