当前位置: 首页 > 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;
        }
      }
    },

}

相关文章:

  • 设计模式之观察者模式
  • oracle (9)Storage Relationship Strut
  • 【Linux】虚拟机部署与发布J2EE项目(Linux版本)
  • 解锁AI语言模型的秘密武器 - 提示工程
  • 知心早安问候语,愿你享受美好的时光,幸福快乐每一天
  • 计算机网络第4章-网络层(1)
  • 用逻辑分析仪观察串口Uart数据波形
  • 如何将你的PC电脑数据迁移到Mac电脑?使用“迁移助理”从 PC 传输到 Mac的具体操作教程
  • 在Java和PostgreSQL枚举之间进行转换的通用方法
  • WIN11如何固定文件夹查看方式
  • Java修仙传之神奇的ES(基础使用)
  • Hive常用DDL操作
  • centos7如何使用oxidized备份网络配置
  • Jasypt整合springboot完成对配置文件中有关敏感数据的加密
  • 图片变形的问题
  • 宽带电力载波稳定吗?有丢数据吗?
  • Linux | 文件系统
  • OpenAI将推出ChatGPT Plus会员新功能,有用户反馈将支持上传文件和多模态
  • CCF_A 计算机视觉顶会CVPR2024投稿指南以及论文模板
  • Excel表格密码解密软件 - 轻松解锁忘记的Excel密码
  • 阿胶在那种网站做推广好/app软件推广怎么做
  • 北京家装设计公司/百度搜索关键词排名优化技术
  • 电子网站建设ppt模板/赛雷猴是什么意思
  • wordpress+私信/seo优化方案案例
  • 网站不用域名需要备案吗/注册网站多少钱
  • 网站开发绩效考核与薪酬/网站建设与管理属于什么专业