最终效果
listImg: [
img: [
{ imgUrl: 1, name: ‘党校室内照片’ },
{ imgUrl: 2, name: ‘党校室内照片’ },
{ imgUrl: 3, name: ‘党校室内照片’ },
{ imgUrl: 4, name: ‘党校室内照片’ }
],
img: [
{ imgUrl: 5 name: ‘党校室内照片’ },
{ imgUrl: 6, name: ‘党校室内照片’ },
{ imgUrl: 7, name: ‘党校室内照片’ },
{ imgUrl: 8, name: ‘党校室内照片’ }
]
]
let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
let arrlist = []
let imglist = []
let imglist2= []
for(let i = 0; i < arr.length; i++) {
let obj = {}
obj['imgUrl'] = arr[i]
obj['name'] = '党校外观照片'
arrlist.push(obj)
}
console .log(arrlist)
for(let i = 0, len = arrlist.length; i < len; i += 4) {
imglist.push(arrlist.slice(i, i + 4))
}
console.log(imglist)
for(let i = 0; i < imglist.length; i++) {
let obj = {}
obj['img'] = imglist[i]
imglist2.push(obj)
}
console.log(imglist2)