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