實施例:https://jsfiddle.net/zidski/a0ez5sy9/1/嵌套陣列.MAP沒有循環母陣列
我已經創建稱爲ProjectAPI JSON對象。
const ProjectAPI = {
projects: [
{
name: "PROJECT NAME",
thumbnail: "imageURL",
image: [
"imageURL",
"imageURL",
"imageURL"
]
},{
name: "PROJECT NAME",
thumbnail: "imageURL",
image: [
"imageURL",
"imageURL",
"imageURL"
]
}],
all: function() { return this.projects},
get: function(id) {
const isProject = p => p.number === id
return this.projects.find(isProject)
}
}
然後我使用.MAP得到嵌套圖像:
{
ProjectAPI.all().map(function(item, index) {
return <img className="img" key={index} src={item.image[index]} />
})
}
但被好像通過父陣列循環,所以我結束了6幅圖像,而不是3(在實施例的jsfiddle邊框紅)
我該如何定位嵌套圖像?
'所以我結束了6個圖像,而不是3'你的意思是'3圖像,而不是6'? –
是3張圖片而不是6張。 – user1177860