业务需求详解: 业务需求数据处理-后台API只返回四个字段ABCD,现在数据量较大有20万条,一列上要展示ABCDABCDABCD这么些字段,这时服务端他不会给你做处理,只能前端自己处理了,将对象forEach遍历添加到一个新的obj中,当index%30,当index%31时,当index%3==2时分别push存储到obj对象中
使用框架为vue
.then(res => {
if (res.detail.list == []) {
return false;
}
let that = this;
let obj = {};
var list = [];
res.detail.list.forEach((item, index) => {
if (index % 3 === 0) {
obj.contactsName = item.contactsName;
// console.log(obj.contactsName)
obj.contactsPhoneNum = item.contactsPhoneNum;
obj.contactsCallNum = item.contactsCallNum;
obj.contactsCallTime = item.contactsCallTime;
}
if (index % 3 === 1) {
obj.contactsName1 = item.contactsName;
obj.contactsPhoneNum1 = item.contactsPhoneNum;
obj.contactsCallNum1 = item.contactsCallNum;
obj.contactsCallTime1 = item.contactsCallTime;
}
if (index % 3 === 2) {
obj.contactsName2 = item.contactsName;
obj.contactsPhoneNum2 = item.contactsPhoneNum;
obj.contactsCallNum2 = item.contactsCallNum;
obj.contactsCallTime2 = item.contactsCallTime;
list.push(obj);
obj = {};
}
if (index === res.detail.list.length - 1) {
list.push(obj);
obj = {};
}
});
// console.log(list,'list')
that.baseData1.push(list);
that.count = res.detail.count;
this.loading3 = false;
});