当前位置:网站首页>The El tree implementation only displays a certain level of check boxes and selects radio
The El tree implementation only displays a certain level of check boxes and selects radio
2022-04-23 15:27:00 【Elegant pig】
In fact, after this thing is made , It's quite simple .
Let's talk about the idea of implementation first :
Show only one level of check boxes :el-tree Provided in disabled attribute , When we set... For a node disabled After attribute , Then the current node is disabled , So let's find and add disabled The class name of the node check box , adopt display:none Just hide it , I've already found it here , The code is posted below .
The radio : You all know that there are many check boxes , But demand is always unsatisfactory , You have to choose a single choice , It's not hard . After the election , Get the currently selected node object , Then reset the selected node ( Only the currently selected nodes are set , Single choice )
The key codes are as follows :
el-tree: Components
Note here that it is best to set node-key Otherwise, something might go wrong
<el-tree
:data="treeData"
:props="{ children: 'children', label: 'label' }"
show-checkbox
@check-change="checkChange"
ref="Tree"
:check-strictly="true"
node-key="id"
></el-tree>
After getting the tree data from the back end :
Because I can only choose the innermost layer here ( No children The hierarchy of ) So add... Recursively disabled attribute , No, children Do not add
// Get the right tree data
getTreeList() {
/**
* ajax Got the data and this.treeData = data.data
* After acquisition
*/
this.setDisabled(this.treeData)
},
// Xiang you children Add... On the node of disabled attribute
setDisabled(treeData) {
treeData.forEach(item => {
if(item.children && item.children.length) {
item.disabled = true
this.setDisabled(item.children)
}
})
},
then css:
Just set this here , There are disabled Property will not display the check box
/* Hide el-tree There is disabled Attribute frame */
/deep/.el-checkbox__input.is-disabled{
display: none;
}
Then you can only choose one :
// Select the check box to trigger
checkChange(currObj,isChecked) {
if(isChecked) { // After selecting, we will reset the selected node ( Only the currently selected nodes are set , Single choice )
this.$refs.Tree.setCheckedNodes([currObj])
}
},
effect :

版权声明
本文为[Elegant pig]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204231523549534.html
边栏推荐
- JS - implémenter la fonction de copie par clic
- Do keyword search, duplicate keyword search, or do not match
- Detailed explanation of C language knowledge points - data types and variables [2] - integer variables and constants [1]
- Rsync + inotify remote synchronization
- fatal error: torch/extension.h: No such file or directory
- Comparaison du menu de l'illustrateur Adobe en chinois et en anglais
- 重定向和请求转发详解
- Leetcode学习计划之动态规划入门day3(198,213,740)
- 自主作业智慧农场创新论坛
- Lotus DB design and Implementation - 1 Basic Concepts
猜你喜欢

Deep learning - Super parameter setting

On the day of entry, I cried (mushroom street was laid off and fought for seven months to win the offer)

8.4 realization of recurrent neural network from zero

Byte interview programming question: the minimum number of K
![Detailed explanation of C language knowledge points -- data types and variables [1] - carry counting system](/img/95/3b38a550e78b3467c4a756af073d0a.png)
Detailed explanation of C language knowledge points -- data types and variables [1] - carry counting system

Advanced version of array simulation queue - ring queue (real queuing)

The win10 taskbar notification area icon is missing

如何设计一个良好的API接口?
![Design of digital temperature monitoring and alarm system based on DS18B20 single chip microcomputer [LCD1602 display + Proteus simulation + C program + paper + key setting, etc.]](/img/c6/5241de0d670da3dae136a3047c6160.jpg)
Design of digital temperature monitoring and alarm system based on DS18B20 single chip microcomputer [LCD1602 display + Proteus simulation + C program + paper + key setting, etc.]

Basic operation of circular queue (Experiment)
随机推荐
Detailed explanation of kubernetes (IX) -- actual combat of creating pod with resource allocation list
Byte interview programming question: the minimum number of K
js——实现点击复制功能
Mysql database explanation (8)
Nuxt project: Global get process Env information
Detailed explanation of MySQL connection query
After time judgment of date
Rsync + inotify remote synchronization
Node. JS ODBC connection PostgreSQL
fatal error: torch/extension.h: No such file or directory
移动app测试如何进行?
PSYNC synchronization of redis source code analysis
Llvm - generate local variables
移动app软件测试工具有哪些?第三方软件测评小编分享
YML references other variables
Llvm - generate if else and pH
js——實現點擊複制功能
win10 任务栏通知区图标不见了
Explanation 2 of redis database (redis high availability, persistence and performance management)
Redis cluster principle