【发布时间】:2017-05-13 20:57:47
【问题描述】:
我有一个来自服务器的对象数组。我用它在屏幕上显示卡片。我想每 X 卡插入一张“广告卡”。我以为我已经使用以下代码在网络上完成了此操作,但它似乎不适用于我的 react-native 应用程序。
class DeckArea extends React.Component {
constructor(props){
super(props);
}
render(){
let { data, likeJob } = this.props;
// place an object into the array of jobs data
data.jobs.forEach((item, i) => {
let remainder = i%4;
if (remainder === 0) {
console.log(remainder === 0)
data.jobs.splice(i, 0,{ isAd: true, _id: uuidV4() })
}
});
return (
<View style={styles.container}>
<Swipe
data={data.jobs}
renderCard={(job) => {
//check if isAd === true,
// if so, show the AdCard not the deck card
if (job.isAd) {
return <AdCard adsManager={adsManager} />
}
return <DeckCard job={job} isLikedCard={false} />
}}
/>
</View>
);
}
}
我已经做了一些快速测试,问题肯定在这里发生:
data.jobs.forEach((item, i) => {
let remainder = i%4;
if (remainder === 0) {
console.log(remainder === 0)
data.jobs.splice(i, 0,{ isAd: true, _id: uuidV4()})
}
});
导致“试图分配给只读属性”
其他资源:
【问题讨论】:
标签: javascript reactjs react-native