Javascript 使用map在react上的2个循环后添加类
我试图在两个循环之后添加类。它正在工作,但无法隐藏Javascript 使用map在react上的2个循环后添加类,javascript,reactjs,loops,ecmascript-6,Javascript,Reactjs,Loops,Ecmascript 6,我试图在两个循环之后添加类。它正在工作,但无法隐藏{x++}文本。你怎么能隐瞒这一点?我也尝试过使用索引 const workdata = this.state.worksData.map((work, index) => ( <div className={ x % 3 == 0 ? "col-lg-4 col-md-6 offset-lg
{x++}
文本。你怎么能隐瞒这一点?我也尝试过使用索引
const workdata = this.state.worksData.map((work, index) => (
<div
className={
x % 3 == 0
? "col-lg-4 col-md-6 offset-lg-0 offset-md-3"
: "col-lg-4 col-md-6"
}
key={index}
>
<div
className={
x % 3 == 0 ? "single-box" : "single-box with-line"
}
>
<span>{work.position}</span>
</div>
{x++}
</div>
));
const workdata=this.state.worksData.map((工作,索引)=>(
{work.position}
{x++}
));
使用for循环就可以了
for (let i = 0; i < data.length; i++) {
if (x % 3 == 0) {
console.log("Class", data[i]);
} else {
console.log(data[i]);
}
x++;
}
for(设i=0;i
您应该使用现有的索引属性,而不是创建新的x。请参阅下面的示例代码
const workdays = this.state.worksData.map((work, index) => (
<div
className={
(index + 1) % 3 == 0
? "col-lg-4 col-md-6 offset-lg-0 offset-md-3"
: "col-lg-4 col-md-6"
}
>
<div
className={
(index + 1) % 3 == 0 ? "single-box" : "single-box with-line"
}
>
<span>{work.position}</span>
</div>
</div>
));
const workdays=this.state.worksData.map((工作,索引)=>(
{work.position}
));
您应该使用现有的索引属性,而不是创建新的x。请参阅下面的示例代码
const workdays = this.state.worksData.map((work, index) => (
<div
className={
(index + 1) % 3 == 0
? "col-lg-4 col-md-6 offset-lg-0 offset-md-3"
: "col-lg-4 col-md-6"
}
>
<div
className={
(index + 1) % 3 == 0 ? "single-box" : "single-box with-line"
}
>
<span>{work.position}</span>
</div>
</div>
));
const workdays=this.state.worksData.map((工作,索引)=>(
{work.position}
));
我希望在两个循环之后添加类<代码>与第3项、第6项、第9项类似。你能做到吗?是的,只要把(索引+1)%3==0。它的行为将与您已经使用for循环实现的行为相同。我希望该类在两个循环之后添加<代码>与第3项、第6项、第9项类似。你能做到吗?是的,只要把(索引+1)%3==0。它的行为将与您已经使用for循环实现的行为相同。