当前位置:网站首页>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
边栏推荐
- Mysql database explanation (10)
- Leetcode学习计划之动态规划入门day3(198,213,740)
- Detailed explanation of C language knowledge points - data types and variables [2] - integer variables and constants [1]
- Detailed explanation of redirection and request forwarding
- API gateway / API gateway (II) - use of Kong - load balancing
- Educational codeforces round 127 A-E problem solution
- Educational Codeforces Round 127 A-E题解
- Llvm - generate if else and pH
- 激活函数的优缺点和选择
- Advanced version of array simulation queue - ring queue (real queuing)
猜你喜欢

让阿里P8都为之着迷的分布式核心原理解析到底讲了啥?看完我惊了

win10 任务栏通知区图标不见了

Functions (Part I)

我的 Raspberry Pi Zero 2W 折腾笔记,记录一些遇到的问题和解决办法

What exactly does the distributed core principle analysis that fascinates Alibaba P8? I was surprised after reading it

Knn,Kmeans和GMM

Have you learned the basic operation of circular queue?

Tencent has written a few words, Ali has written them all for a month

8.4 realization of recurrent neural network from zero

Advanced version of array simulation queue - ring queue (real queuing)
随机推荐
Will golang share data with fragment append
Analysis of common storage types and FTP active and passive modes
regular expression
MySQL InnoDB transaction
软件性能测试报告起着什么作用?第三方测试报告如何收费?
Openfaas practice 4: template operation
Detailed explanation of C language knowledge points -- first understanding of C language [1] - vs2022 debugging skills and code practice [1]
The wechat applet optimizes the native request through the promise of ES6
asp. Net method of sending mail using mailmessage
Llvm - generate local variables
Do keyword search, duplicate keyword search, or do not match
木木一路走好呀
Deep learning - Super parameter setting
X509 certificate cer format to PEM format
Kubernetes详解(十一)——标签与标签选择器
Llvm - generate addition
电脑怎么重装系统后显示器没有信号了
redis-shake 使用中遇到的错误整理
Detailed explanation of kubernetes (IX) -- actual combat of creating pod with resource allocation list
通过 PDO ODBC 将 PHP 连接到 MySQL