【发布时间】:2020-03-24 22:06:14
【问题描述】:
我正在尝试从我的数据库中获取嵌套项,但不知道如何。
我的数据库看起来像:
GET /dwelling/room/
[
{
"room_id": 1,
"room_name": "Living Room",
"room_data": [
{
"id": 1,
"temperature": "5,15,9"
...
我目前正在使用:
fetch('https://.../dwelling/room/', {
method: 'GET',
}).then(resp => resp.json())
.then(resp => this.setState({room: resp}))
.catch(error => console.log(error))
}
从数据库中获取数据以及
{props.room.map(room => {
return (
<React.Fragment>
<div>{room.room_name}<div>
</React.Fragment>
...
我能够获取 room_id 和 room_name 的数据,但无法从 room_data 中获取任何内容。我希望能够将温度放入图表中,但我什至无法将数据打印在列表中。我将不胜感激任何帮助!谢谢!
【问题讨论】:
标签: javascript html reactjs