Javascript 映射JSON对象-ReactJS
我正在获取一个json对象作为响应,控制台日志显示如下响应Javascript 映射JSON对象-ReactJS,javascript,reactjs,Javascript,Reactjs,我正在获取一个json对象作为响应,控制台日志显示如下响应 MyFormName: Array(5) 0: {question: "Q1", type: "star"} 1: {question: "Q1", type: "star"} 2: {question: "Q1", type: "star"} 3: {question: "Q1", type: "star"} 4: {question: "Q1", type: "star"} 如何映射此对象,以便显示每个对象中的数据 我试过这样的东
MyFormName: Array(5)
0: {question: "Q1", type: "star"}
1: {question: "Q1", type: "star"}
2: {question: "Q1", type: "star"}
3: {question: "Q1", type: "star"}
4: {question: "Q1", type: "star"}
如何映射此对象,以便显示每个对象中的数据
我试过这样的东西。我的json对象处于完整状态,并尝试了以下方法
return Object.keys(this.state.fullForm).map((item, key) => {
return (
<div className="overflow_hidden" key={key}>
<div>{key + 1}</div>
<div>{item.question}</div>
</div>
)
});
但在这里,我为item获取的值是MyFormName。我想映射MyFormName中的对象。我该怎么做
this.state.fullForm[Object.keys(this.state.fullForm)[0]].map(item, key) => {
//your logic here
})
它将获取fullForm的第一项,在本例中,它是数组中MyFormName的值,然后执行。map您可以试试this.state.fullForm.MyFormNameObject.keysthis.state.fullForm吗。可以根据响应类型更改MyFormName.mapMyFormName。所以我不能直接使用这个名字