js利用filter()给数组去重

 /**
  * 根据唯一标识name来对数组进行过滤,达到数据去重效果
  * */
  unique(arr) {
      const res = new Map();
      return arr.filter((arr) => !res.has(arr.processName) && res.set(arr.processName, 1))
  },
/**
* 调用数组去重方法
*/
getMyApplicationData(){
         this.queryParam.current = this.filterParams.page;
         this.queryParam.size=this.filterParams.pageSize;
         this.$ajax.get('/apply/getByPage',this.queryParam).then(res =>{
             if (res.result.records.length<=0){
                 this.loading = true;
             }else {
                 this.loading = false;
             }
             if (this.filterParams.page == 1){
                 this.myApplicationList = res.result.records
             }else {
                 this.myApplicationList = this.myApplicationList.concat(res.result.records);
             }
             if (this.myApplicationList.length>0) {
                 this.section.processName = this.unique(this.myApplicationList);
             }
             this.filterParams.page++;
             if (res.result.records.length <20){
                 setTimeout(()=>{
                   this.$refs.compscroll&&this.$refs.compscroll.nomore(this.filterParams.page-2)
                 },30)
             }
         });
     },
发布了17 篇原创文章 · 获赞 0 · 访问量 202

猜你喜欢

转载自blog.csdn.net/qq_41444226/article/details/103901997
今日推荐