实施例: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