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;
                }
              }
            }
  • 相关阅读:
    使用T4为数据库自动生成实体类
    asp.net 下OnClientClick的妙用
    使用缓存的9大误区(上)
    使用缓存的9大误区(下)
    毕业后的五年拉开大家差距的原因在哪里
    mysql字符集
    redhat网络基础配置
    mysql远程连接问题
    Hibernate hql语句修改部分字段
    JQuery使用方法总结
  • 原文地址:https://www.cnblogs.com/Byme/p/14415374.html
Copyright © 2011-2022 走看看