【发布时间】:2021-06-20 00:42:40
【问题描述】:
任何人都可以给我任何建议吗?我正在尝试在每 2 个内容中添加一个项目。我看不出代码有什么问题,但为什么 MyAds 编号在我的所有广告条目中都重复出现?它应该从 MyAds0 开始并添加。
MyAds2
Content1
Content2
MyAds2
Content3
Content4
MyAds2
Content5
这是我的代码
const dummyData = [
{
name: 'Content1',
subtitle: 'Content1'
},
{
name: 'Content2',
subtitle: 'Content2'
},
{
name: 'Content3',
subtitle: 'Content3'
},
{
name: 'Content4',
subtitle: 'Content4'
},
{
name: 'Content5',
subtitle: 'Content5'
},
]
let TheData = InsertContent();
function InsertContent () {
let thisdata = [];
let adscounter = 0;
let tmpData = [ {name:'tmp', subtitle:'tmp'}];
for (let i=0; i < dummyData.length; i++){
if (Number.isInteger(i/2)) {
tmpData[0].name = 'MyAds' + adscounter;
tmpData[0].subtitle = 'My MyAds Sub' + adscounter;
thisdata = [...thisdata, tmpData[0]];
adscounter = adscounter + 1;
}
thisdata = [...thisdata, dummyData[i]];
}
return thisdata;
}
【问题讨论】:
标签: arrays react-native