react js无法读取未定义的属性'id'

我在Spring Boot中使用React。

当我尝试获取前端中的所有值时,出现错误:

Cannot read property 'id' of undefined

I fetch in componentDidMount:

componentDidMount() {
  axios.get("http://localhost:8080/rfx/all")
  .then(response => response.data)
  .then((data) => {
    this.setState({ listrfx : data })
  })
}

REndering:

{
  this.state.listrfx.map(listrfx => (
     <tr key={listrfx.id}>  
       <th scope="row">{listrfx.id}</th>
       <td>{listrfx.code.id}</td>

   ))
}

code.id is foreign key in database and this is the type object please what I should to do

评论