gpt4 book ai didi

javascript - 在 React 中每 x 个项目插入一个图像

转载 作者:行者123 更新时间:2023-11-30 11:11:02 26 4
gpt4 key购买 nike

我有一个项目列表,需要在每 10 个项目之间渲染一个图像。项目应在二维网格中呈现,图像应显示在新行中。

应该是这样的: enter image description here

最佳答案

这是我认为您可以使用的一种解决方案:

<div id="container" style={{display: 'flex', flexDirection: 'row', flexWrap: 'wrap'}}>
{arrayList.map((listItem, index) => {
const cardinalIndex = index + 1;
const item = !(cardinalIndex % 10) ? (
<React.Fragment>
<div id="item" style={{flex: '1 1 25%'}}>
{listItem}
</div>
<img style={{flex: '1 1 100%'}} src="" />
</React.Fragment>
) : (
<div id="item" style={{flex: '1 1 25%'}}>
{listItem}
</div>
);
return item;
})}

关于javascript - 在 React 中每 x 个项目插入一个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53685969/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com