我在如下所示的 react 组件中有 render 方法,它显示 4 x 4 网格。
我想将产品分成 4 组,我该怎么做?
比如我有12个产品,3组4个,我需要展示
XXXX
XXXX
XXXX
我可以有 productList1、productList2、productList3,但我需要它是可扩展的,例如网格可能需要 40 个产品,所以是 10 x 4 网格。
render() {
let productList = this.props.products.map( (p, i) => {
if(i < 4){
return (
<ul key={i}><li>{p.name}</li></ul>
);
} else {
return (
<span>not sure</span>
);
}
});
return (
<section>
{/* 4 products */}
<div className="row">
{productList}
</div>
{/* the next 4 */}
<div className="row">
{productList2}
</div>
{/* and the next 4 */}
<div className="row">
{productList3}
</div>
</section>
)
}