当前位置: 首页 > news >正文

elementUI树节点全选,反选,半选状态

// <template>部分
<div class="check-block"><el-divider></el-divider><el-checkbox :indeterminate="indeterminate" v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox><el-divider></el-divider><el-tree :data="templateList" show-checkbox default-expand-all node-key="id" ref="tree" highlight-current :props="defaultProps" @check="changeCheck"></el-tree></div>data(){return {indeterminate: false,checkAll: false,templateList: [],treeData: [],}
},
methods:{
handleCheckAllChange() {if (this.checkAll) {for (let i = 0; i < this.templateList.length; i++) {if (this.$refs.tree.getNode(this.templateList[i]).disabled == false) {this.$refs.tree.setChecked(this.templateList[i].id, true, true);}}this.treeData = this.$refs.tree.getCheckedNodes(false, true).map((i) => i.id);this.indeterminate = false;} else {this.$refs.tree.setCheckedNodes([]);this.treeData = [];this.indeterminate = false;}},changeCheck() {this.treeData = this.$refs.tree.getCheckedNodes(false, true).map((i) => i.id);let arr = [];// treeData是所有的节点,templateList是所有父节点,所以还需要遍历treeData取出父节点再将length和templateList做比较this.treeData.map((item) => {if (this.$refs.tree.getNode(item).isLeaf == false) {arr.push(item);}});if (arr.length) {if (arr.length == this.templateList.length) {this.checkAll = true;this.indeterminate = false;} else if (arr.length < this.templateList.length) {console.log(1111);this.checkAll = false;this.indeterminate = true;} else {this.checkAll = false;this.indeterminate = false;}}},}

http://www.lryc.cn/news/216165.html

相关文章:

  • Kafka、RabbitMQ、RocketMQ中间件的对比
  • Mac 创建并使用 .zshrc 文件
  • Unity3D移动开发如何依据性能选择Shader
  • 基于stm32F4的智能宠物喂食器的设计:LVGL界面、定时喂食喂水通风
  • jumpserver堡垒机docker方式安装部署
  • 在基于亚马逊云科技的湖仓一体架构上构建数据血缘的探索和实践
  • VScode clangd 插件浏览 linux 源码
  • GZ035 5G组网与运维赛题第8套
  • 《golang设计模式》第三部分·行为型模式-02-命令模式(Command)
  • 【linux进程控制(一)】进程终止--如何干掉一个进程?
  • 言情小说怎么推广?如何推广网络小说?
  • TensorFlow 的应用场景有哪些
  • JAVA提取嵌套夹带文件之Apache Tika
  • SSL数字证书服务
  • 浅谈安科瑞直流电表在荷兰光伏充电桩系统中的应用
  • 淘宝详情API接口怎么实现大数据分析和商品价格监控
  • 智能政务,办事更轻松!拓世法宝AI智慧政务数字人一体机,重新定义你的政务办理体验!
  • WebBits库如何使用
  • 通过netstat命令查看Linux的端口占用
  • 不用动脑小白也能制作出精美的电子杂志
  • 【计算系统】5分钟了解超算,高性能计算,并行计算,分布式计算,网格计算,集群计算以及云计算的区别
  • 6大场景,玩转ChatGPT!
  • 工业废水再利用在哪些地方
  • Spring Cloud的ElasticSearch的进阶学习
  • WordPress恢复时候遇到的几个问题
  • 设备码解释
  • 基于Docker-consul容器服务更新与发现
  • firefox浏览器添加自定义搜索引擎方法
  • redis rdb aof
  • 浮动模块布局