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;
            }
          }
        }

 

posted @ 2021-02-19 11:42  abcByme  阅读(178)  评论(0编辑  收藏  举报