el-tree勾选后退出再打开显示之前已经勾选的

2024-01-25 00:04

本文主要是介绍el-tree勾选后退出再打开显示之前已经勾选的,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

官网文档

element-ui官网文档有默认展开和默认选中

<el-tree:data="data"show-checkboxnode-key="id":default-expanded-keys="[2, 3]":default-checked-keys="[5]":props="defaultProps">
</el-tree><script>export default {data() {return {data: [{id: 1,label: '一级 1',children: [{id: 4,label: '二级 1-1',children: [{id: 9,label: '三级 1-1-1'}, {id: 10,label: '三级 1-1-2'}]}]}, {id: 2,label: '一级 2',children: [{id: 5,label: '二级 2-1'}, {id: 6,label: '二级 2-2'}]}, {id: 3,label: '一级 3',children: [{id: 7,label: '二级 3-1'}, {id: 8,label: '二级 3-2'}]}],defaultProps: {children: 'children',label: 'label'}};}};
</script>

可以看出  :default-checked-keys="[5]"绑定的是一个数组,元素是每个勾选框的id

html:

<el-treeref="tree":data="memberList"show-checkboxdefault-expand-allnode-key="id"highlight-current:props="defaultProps":filter-node-method="filterNode"
></el-tree>

memberList数据样式为(可以看出根节点多了个teamFlag):

[{"id": "F92FE4F9C6F95E18E055000000000001","userName": "A班组","memberList": [{"id": "F92FE4F9C6FA5E18E055000000000001","teamId": "F92FE4F9C6F95E18E055000000000001","userId": "0fbd222725c748299fdc178987569d4b","userName": "小阮","teamType": null},{"id": "F92FE4F9C6FB5E18E055000000000001","teamId": "F92FE4F9C6F95E18E055000000000001","userId": "9d16ac4119064bbe865102494137a3c8","userName": "tw2t","teamType": null},{"id": "F92FE4F9C6FC5E18E055000000000001","teamId": "F92FE4F9C6F95E18E055000000000001","userId": "d55760ebd5c04f2c869ab084be6f4e6b","userName": "tw2leader","teamType": null},{"id": "F92FE4F9C6FD5E18E055000000000001","teamId": "F92FE4F9C6F95E18E055000000000001","userId": "cdf0c8dcf93f4dfc8602ff59e0b8d191","userName": "tw3t","teamType": null},{"id": "F92FE4F9C6FE5E18E055000000000001","teamId": "F92FE4F9C6F95E18E055000000000001","userId": "885d106031784e6caa2f9fcfb3feab32","userName": "TWTWO","teamType": null},{"id": "F92FE4F9C6FF5E18E055000000000001","teamId": "F92FE4F9C6F95E18E055000000000001","userId": "eb0533610a48411aa6124484aef107a1","userName": "tw2","teamType": null},{"id": "F92FE4F9C7005E18E055000000000001","teamId": "F92FE4F9C6F95E18E055000000000001","userId": "0998d44318fa44f3bb033030adcea1d4","userName": "rh","teamType": null}],"teamFlag": "team"},{"id": "F92FE5D8EB055E14E055000000000001","userName": "B班组","memberList": [{"id": "F92FE5D8EB065E14E055000000000001","teamId": "F92FE5D8EB055E14E055000000000001","userId": "9eb123238f464b5f9ce2b55d98a7151f","userName": "tw3","teamType": null},{"id": "F92FE5D8EB075E14E055000000000001","teamId": "F92FE5D8EB055E14E055000000000001","userId": "a687747a84b541b9a5dadb6cedbaac60","userName": "tw3s","teamType": null},{"id": "F92FE5D8EB085E14E055000000000001","teamId": "F92FE5D8EB055E14E055000000000001","userId": "7ed742cf308a4e6e876d19c85ab87bc5","userName": "tw2s","teamType": null},{"id": "F92FE5D8EB095E14E055000000000001","teamId": "F92FE5D8EB055E14E055000000000001","userId": "1c4745174b2443bcb0f692b4206dd565","userName": "陈爱国","teamType": null},{"id": "F92FE5D8EB0A5E14E055000000000001","teamId": "F92FE5D8EB055E14E055000000000001","userId": "37a3167e7bf34e7794080cf3580206ea","userName": "tw1","teamType": null},{"id": "F92FE5D8EB0B5E14E055000000000001","teamId": "F92FE5D8EB055E14E055000000000001","userId": "fbbbf36302d444be8a6b3e01cbc761c4","userName": "tw4s","teamType": null},{"id": "F92FE5D8EB0C5E14E055000000000001","teamId": "F92FE5D8EB055E14E055000000000001","userId": "16d7b52ec5c24bde8b0db1ea76f3c2d1","userName": "tw4t","teamType": null},{"id": "F92FE5D8EB0D5E14E055000000000001","teamId": "F92FE5D8EB055E14E055000000000001","userId": "add97170833e4321a90440f9a80ff650","userName": "tw4","teamType": null},{"id": "F92FE5D8EB0E5E14E055000000000001","teamId": "F92FE5D8EB055E14E055000000000001","userId": "584f437636f04ffca8cce346a80c4b17","userName": "tw1leader","teamType": null}],"teamFlag": "team"},{"id": "F92FE5D8EB0F5E14E055000000000001","userName": "C班组","memberList": [],"teamFlag": "team"},{"id": "0B2EE330883E04CCE065000000000001","userName": "D班组","memberList": [{"id": "0B2EE330883F04CCE065000000000001","teamId": "0B2EE330883E04CCE065000000000001","userId": "52d863f6232f45cf9abbdb483e9349ac","userName": "塔台讲评室","teamType": null},{"id": "0B2EE330884004CCE065000000000001","teamId": "0B2EE330883E04CCE065000000000001","userId": "d35a2f81166b47c5aad011a665863b2a","userName": "塔台","teamType": null},{"id": "0B2EE330884104CCE065000000000001","teamId": "0B2EE330883E04CCE065000000000001","userId": "6f349b9acd0a431ab77797afdc987202","userName": "TWONE","teamType": null}],"teamFlag": "team"}
]

第一次勾选完生成this.checkedMemberList发送给父数组:

this.checkedMemberList数据(把有teamFlag的删除了,就是删除了根节点其实可以不删):

[{"id": "F92FE4F9C6FA5E18E055000000000001","teamId": "F92FE4F9C6F95E18E055000000000001","userId": "0fbd222725c748299fdc178987569d4b","userName": "小阮","teamType": null},{"id": "F92FE4F9C6FB5E18E055000000000001","teamId": "F92FE4F9C6F95E18E055000000000001","userId": "9d16ac4119064bbe865102494137a3c8","userName": "tw2t","teamType": null},{"id": "F92FE4F9C6FC5E18E055000000000001","teamId": "F92FE4F9C6F95E18E055000000000001","userId": "d55760ebd5c04f2c869ab084be6f4e6b","userName": "tw2leader","teamType": null},{"id": "F92FE4F9C6FD5E18E055000000000001","teamId": "F92FE4F9C6F95E18E055000000000001","userId": "cdf0c8dcf93f4dfc8602ff59e0b8d191","userName": "tw3t","teamType": null},{"id": "F92FE4F9C6FE5E18E055000000000001","teamId": "F92FE4F9C6F95E18E055000000000001","userId": "885d106031784e6caa2f9fcfb3feab32","userName": "TWTWO","teamType": null},{"id": "F92FE4F9C6FF5E18E055000000000001","teamId": "F92FE4F9C6F95E18E055000000000001","userId": "eb0533610a48411aa6124484aef107a1","userName": "tw2","teamType": null},{"id": "F92FE4F9C7005E18E055000000000001","teamId": "F92FE4F9C6F95E18E055000000000001","userId": "0998d44318fa44f3bb033030adcea1d4","userName": "rh","teamType": null}
]

在父组件中处理子组件传过去的选择的元素(主要是this.form.selectedMembe):

    //选择参加人员窗口关闭时handleMemberDialog(flag, memberList) {this.selectMemberVisible = flag;this.form.selectedMember = memberList;this.form.memberName = memberList.map((item) => {return item.userName;}).join(",");let arrList = this.form.memberName.split(",");this.$set(this.form, "checkboxGroup", arrList);},

父组件中对子组件的传递:

子组件处理父组件传递过来的数据(就是获取selectedMember数组的元素的id就够了)

openInit() {if (this.selectedMember && this.selectedMember.length > 0) {this.$refs.tree.setCheckedKeys(this.selectedMember.map((item) => {return item.id;}));} else {this.$refs.tree.setCheckedKeys([]);}},

          this.selectedMember.map((item) => return item.id })

["F92FE4F9C6FA5E18E055000000000001","F92FE4F9C6FB5E18E055000000000001","F92FE4F9C6FC5E18E055000000000001","F92FE4F9C6FD5E18E055000000000001","F92FE4F9C6FE5E18E055000000000001","F92FE4F9C6FF5E18E055000000000001","F92FE4F9C7005E18E055000000000001"
]

这篇关于el-tree勾选后退出再打开显示之前已经勾选的的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/641464

相关文章

golang1.23版本之前 Timer Reset方法无法正确使用

《golang1.23版本之前TimerReset方法无法正确使用》在Go1.23之前,使用`time.Reset`函数时需要先调用`Stop`并明确从timer的channel中抽取出东西,以避... 目录golang1.23 之前 Reset ​到底有什么问题golang1.23 之前到底应该如何正确的

如何设置vim永久显示行号

《如何设置vim永久显示行号》在Linux环境下,vim默认不显示行号,这在程序编译出错时定位错误语句非常不便,通过修改vim配置文件vimrc,可以在每次打开vim时永久显示行号... 目录设置vim永久显示行号1.临时显示行号2.永www.chinasem.cn久显示行号总结设置vim永久显示行号在li

el-select下拉选择缓存的实现

《el-select下拉选择缓存的实现》本文主要介绍了在使用el-select实现下拉选择缓存时遇到的问题及解决方案,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的... 目录项目场景:问题描述解决方案:项目场景:从左侧列表中选取字段填入右侧下拉多选框,用户可以对右侧

电脑显示hdmi无信号怎么办? 电脑显示器无信号的终极解决指南

《电脑显示hdmi无信号怎么办?电脑显示器无信号的终极解决指南》HDMI无信号的问题却让人头疼不已,遇到这种情况该怎么办?针对这种情况,我们可以采取一系列步骤来逐一排查并解决问题,以下是详细的方法... 无论你是试图为笔记本电脑设置多个显示器还是使用外部显示器,都可能会弹出“无HDMI信号”错误。此消息可能

如何提高Redis服务器的最大打开文件数限制

《如何提高Redis服务器的最大打开文件数限制》文章讨论了如何提高Redis服务器的最大打开文件数限制,以支持高并发服务,本文给大家介绍的非常详细,感兴趣的朋友跟随小编一起看看吧... 目录如何提高Redis服务器的最大打开文件数限制问题诊断解决步骤1. 修改系统级别的限制2. 为Redis进程特别设置限制

第10章 中断和动态时钟显示

第10章 中断和动态时钟显示 从本章开始,按照书籍的划分,第10章开始就进入保护模式(Protected Mode)部分了,感觉从这里开始难度突然就增加了。 书中介绍了为什么有中断(Interrupt)的设计,中断的几种方式:外部硬件中断、内部中断和软中断。通过中断做了一个会走的时钟和屏幕上输入字符的程序。 我自己理解中断的一些作用: 为了更好的利用处理器的性能。协同快速和慢速设备一起工作

安卓链接正常显示,ios#符被转义%23导致链接访问404

原因分析: url中含有特殊字符 中文未编码 都有可能导致URL转换失败,所以需要对url编码处理  如下: guard let allowUrl = webUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {return} 后面发现当url中有#号时,会被误伤转义为%23,导致链接无法访问

C#实战|大乐透选号器[6]:实现实时显示已选择的红蓝球数量

哈喽,你好啊,我是雷工。 关于大乐透选号器在前面已经记录了5篇笔记,这是第6篇; 接下来实现实时显示当前选中红球数量,蓝球数量; 以下为练习笔记。 01 效果演示 当选择和取消选择红球或蓝球时,在对应的位置显示实时已选择的红球、蓝球的数量; 02 标签名称 分别设置Label标签名称为:lblRedCount、lblBlueCount

ORACLE 11g 创建数据库时 Enterprise Manager配置失败的解决办法 无法打开OEM的解决办法

在win7 64位系统下安装oracle11g,在使用Database configuration Assistant创建数据库时,在创建到85%的时候报错,错误如下: 解决办法: 在listener.ora中增加对BlueAeri-PC或ip地址的侦听,具体步骤如下: 1.启动Net Manager,在“监听程序”--Listener下添加一个地址,主机名写计

lvgl8.3.6 控件垂直布局 label控件在image控件的下方显示

在使用 LVGL 8.3.6 创建一个垂直布局,其中 label 控件位于 image 控件下方,你可以使用 lv_obj_set_flex_flow 来设置布局为垂直,并确保 label 控件在 image 控件后添加。这里是如何步骤性地实现它的一个基本示例: 创建父容器:首先创建一个容器对象,该对象将作为布局的基础。设置容器为垂直布局:使用 lv_obj_set_flex_flow 设置容器