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

相关文章

第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 设置容器

树(Tree)——《啊哈!算法》

树 什么是树?树是一种特殊的图,不包含回路的连通无向树。 正因为树有着“不包含回路”这个特点,所以树就被赋予了很多特性。 一棵树中的任意两个结点有且仅有唯一的一条路径连通。一棵树如果有n个结点,那么它一定恰好有n-1条边。在一棵树中加一条边将会构成一个回路。 一棵树有且只有一个根结点。 没有父结点的结点称为根结点(祖先)。没有子结点的结点称为叶结点。如果一个结点既不是根结点也不是叶

C# dateTimePicker 显示年月日,时分秒

dateTimePicker默认只显示日期,如果需要显示年月日,时分秒,只需要以下两步: 1.dateTimePicker1.Format = DateTimePickerFormat.Time 2.dateTimePicker1.CustomFormat = yyyy-MM-dd HH:mm:ss Tips:  a. dateTimePicker1.ShowUpDown = t

vue2实践:el-table实现由用户自己控制行数的动态表格

需求 项目中需要提供一个动态表单,如图: 当我点击添加时,便添加一行;点击右边的删除时,便删除这一行。 至少要有一行数据,但是没有上限。 思路 这种每一行的数据固定,但是不定行数的,很容易想到使用el-table来实现,它可以循环读取:data所绑定的数组,来生成行数据,不同的是: 1、table里面的每一个cell,需要放置一个input来支持用户编辑。 2、最后一列放置两个b

小程序button控件上下边框的显示和隐藏

问题 想使用button自带的loading图标功能,但又不需要button显示边框线 button控件有一条淡灰色的边框,在控件上了样式 border:none; 无法让button边框隐藏 代码如下: <button class="btn">.btn{border:none; /*一般使用这个就是可以去掉边框了*/} 解决方案 发现button控件有一个伪元素(::after

MFC中Spin Control控件使用,同时数据在Edit Control中显示

实现mfc spin control 上下滚动,只需捕捉spin control 的 UDN_DELTAPOD 消息,如下:  OnDeltaposSpin1(NMHDR *pNMHDR, LRESULT *pResult) {  LPNMUPDOWN pNMUpDown = reinterpret_cast(pNMHDR);  // TODO: 在此添加控件通知处理程序代码    if