【发布时间】:2019-03-24 03:58:48
【问题描述】:
render() {
return (
<p>{this.state.recipes[0].title}</p> // This is what I believe should work - Ref Pic #1
// <p>{this.state.recipes[0]}</p> // This was trying random stuff to see what happens - Ref Pic #2
// <p>{this.state.recipes.title}</p> // This was me trying crazy nonsense - Ref Pic #3
)
}
我正在尝试遍历一些 JSON 并得到一些非常不稳定的响应。如果有人想亲自查看 JSON,请访问 this link。
当第一个 p 标签运行时,我得到以下响应: This is my first question, so I can't embed images, I'm sorry.
由于不确定为什么它说 recipes[0] 未定义,我再次运行它,第二个 p 标签单独未注释,我得到以下回复:Still the same question, still can't embed, sorry again.
这个响应真的让我措手不及,因为它引用的键(nid、title 等)是我知道的对象中的键。 “标题”是我想要的。
最后,我只尝试了第三个 p 标签,应用程序实际编译到该标签没有错误,但 p 标签是空的。 Here's what I have in React Devtools, but I still can't embed.
查看
我做错了什么?
【问题讨论】:
-
您是在异步获取 JSON 吗?
标签: javascript json reactjs