zoukankan      html  css  js  c++  java
  • js 去重和过滤

    //去重 

    if ( (this.selectPeopleList != null) & (this.selectPeopleList.length != 0) ) { let arrId = []; let arrName = []; this.selectPeopleList.map((item) => { arrId.push(item.id); arrName.push(item.name); //去重 let x = new Set(arrName); let y = [...x]; // this.info.inspector = arr.join(","); this.info.inspector = y; }); }
    getTypeTree(item, index) {
          console.log(111, index);
          let getCheckedNodes = this.$refs.treeForm.getCheckedNodes(); //获取被勾选的节点
          let getSelectedNodes = this.$refs.treeForm.getSelectedNodes(); //获取被选中的节点
          let getCheckedAndIndeterminateNodes = this.$refs.treeForm.getCheckedAndIndeterminateNodes(); //获取选中及半选节点
          if (getCheckedNodes != null) {
            // this.selectPeopleList = getCheckedNodes;
            console.log("getCheckedNodes", getCheckedNodes);
            //--
            getCheckedNodes
              .filter((item) => {
                //过滤组织
                return item.iconSkin !== "group";
              })
              .map((item) => {
                // return item;
                this.selectPeopleList.push(item.name);
              });
            //--
            // getCheckedNodes.map((item) => {
            //   this.selectPeopleList.push(item.name);
            // });
            //过滤重复的
            this.selectPeopleList = this.selectPeopleList.filter(
              (element, index, self) => {
                return self.indexOf(element) === index;
              }
            );
            this.selectNumber = this.selectPeopleList.length;
            console.log("this.selectPeopleList", this.selectPeopleList);
          }
        },
    // 去除重复的和group;
            let result = [];
            let obj = {};
            for (let i = 0; i < this.selectPeopleListNew.length; i++) {
              if (this.selectPeopleListNew[i].iconSkin !== "group") {
                if (!obj[this.selectPeopleListNew[i].id]) {
                  result.push(this.selectPeopleListNew[i]);
                  obj[this.selectPeopleListNew[i].id] = true;
                }
              }
            }
  • 相关阅读:
    【5】Python之nnlog写日志模块,yagmail发送邮件模块
    【11】Python面向对象:封装和继承(类、函数/方法、重写)
    【5】Java继承
    【4】作业:办公信息化管理系统
    【3】综合案例:学生信息管理
    【2】Java封装
    【1】java面向对象
    【9】综合案例:数组移位与统计
    【8】Java方法
    【7】Java数组之二维数组
  • 原文地址:https://www.cnblogs.com/Byme/p/14415374.html
Copyright © 2011-2022 走看看