-1

I am trying to get nested items from my database and can't figure out how.

My database looks like:

GET /dwelling/room/


[
    {
        "room_id": 1,
        "room_name": "Living Room",
        "room_data": [
            {
                "id": 1,
                "temperature": "5,15,9"
                ...

I am currently using:

    fetch('https://.../dwelling/room/', {
      method: 'GET',
    }).then(resp => resp.json())
      .then(resp => this.setState({room: resp}))
      .catch(error => console.log(error))
  }

to get the data from the database as well as

{props.room.map(room => {

                return (

                    <React.Fragment>
                        <div>{room.room_name}<div>
                    </React.Fragment>
                    ...

I am able to get the data for room_id and room_name but cannot get anything from inside room_data. I want to be able to put the temperature into a graph but I can't even get the data to print out in a list. I would appreciate any help! Thank you!

ajnabz
  • 297
  • 5
  • 25

1 Answers1

0

Judging by your record, you can get room temprature by simply accessing room.room_data[0].temperature

[
    {
        "room_id": 1,
        "room_name": "Living Room",
        "room_data": [
            {
                "id": 1,
                "temperature": "5,15,9"
                ...
Barun Patro
  • 860
  • 4
  • 13