【发布时间】:2017-05-16 11:37:47
【问题描述】:
我是新来的反应。
this.state = { histories: [
{
"qas":[
{"question": "hi1", "answer": "hello1"},
{"question": "hi2", "answer": "hello2"}
]
}
] };
render(){
return (
<div>
<History
histories={this.state.histories} />
</div>
);
}
在单独的组件页面中,我想使用react js通过循环或地图来呈现问答,但是我尝试了地图,它无法识别地图。我试过for循环,但它没有从中获取子属性。
const history = ({histories}) => {
return(
<div>
{histories[0].qas[0].question}
</div>
<div}>
{histories[0].qas[0].answer}
</div>
);
}
【问题讨论】:
-
用
map向我们展示代码 -
在
state.histories上使用map,因为那是数组。
标签: javascript json reactjs ecmascript-6