简单的循环以及从接口获取数组对象的一个字段集合

1.简单的循环字段循环

  if (this.videolist) {
        console.log(111);
        for (let j = 0; j < this.videolist.length; j++) {
          if (this.videolist[j].video) {
            this.showVIdeo = false;
            return;
          } else {
            this.showVIdeo = true;
          }
        }
      } else {
        console.log(222);
        this.showVIdeo = true;
      }

2.使用循环从接口获取数组对象的一个字段集合

   let list= [];
          for (let j = 0; j < res.data.result.xxoptization.length; j++) {
            if(res.data.result.xxoptization[j].video){
              let temporaryItem = {};
              temporaryItem.video = res.data.result.xxoptization[j].video;
              temporaryItem.videoimg = res.data.result.xxoptization[j].videoimg;
              temporaryItem.videoname = res.data.result.xxoptization[j].videoname;
              temporaryItem.title = res.data.result.xxoptization[j].title;
              list.push(temporaryItem);
            }
          }
          this.videolist.push(...list);

猜你喜欢

转载自www.cnblogs.com/Glant/p/10921549.html