我有一个这样的对象数组:{ id, width, height, margin }
. 当我渲染该数组并将该信息应用到像这样反应 konva Rect 组件时:
{
topSide.map((seat, index) => (
<Rect
id={seat.id}
key={seat.id}
fill="brown"
stroke="white"
width={seat.width}
height={seat.height}
x={topSideStartPosition + index * seat.width + seat.margin}
y={y * linesHeight - seat.height - 2}
/>
))
}
所以我的问题是seat.margin
仅适用于 1 个矩形。通常我想为第一个矩形应用一个值,为其余矩形应用另一个值。seat.margin
如果数组中的对象索引为 1,则等于 1;如果对象索引不等于 1,则等于 2。它的外观如下:
结果图像