2 回答

TA貢獻1784條經驗 獲得超9個贊
在我看來,您的 product_images 是產品圖像 ID 的 CSV。如果是這種情況,請嘗試:
{product.product_images.split(',')
.filter(Boolean) // this is to filter out falsy values if necessary
.map(product_image =>
<div key={`${product.id}-${product_image}`}> // concat product id with the image id
<img height='100%' alt='hello' src={`${IMAGE_PATH}${product_image}`} />
</div>
)}

TA貢獻1860條經驗 獲得超9個贊
Object.values((product && product.product_images) || [])
.filter(productImgArr => productImgArr !== null)
.map(productImgArr => productImgArr.join(''))
.map((product_image, index) =>
<div key={`${product_image}-${index}`}>
<img height='100%' alt='hello'
src={"IMAGE_PATH" + product_image} />
</div>
)
添加回答
舉報