When I want to extract the listdate, map hints undefined. When printing the listdate, the map method is displayed. What is this for?
The code is very simple, that is, the react Chinese network example.
Here is the code for PHP:
{"status":0,"records":{ "title": "Here's the book list", "listData": [ {"name": "沙滩搁浅我们的旧时光", "author": "XiaoMing"}, {"name": "女人天生高贵", "author": "XiaoDong"}, {"name": "海是彩色的灰尘", "author": "XiaoXi"} ] }}
This is the REACT code
Reply content:
When I want to extract the listdate, map hints undefined. When printing the listdate, the map method is displayed. What is this for?
The code is very simple, that is, the react Chinese network example.
Here is the code for PHP:
{"status":0,"records":{ "title": "Here's the book list", "listData": [ {"name": "沙滩搁浅我们的旧时光", "author": "XiaoMing"}, {"name": "女人天生高贵", "author": "XiaoDong"}, {"name": "海是彩色的灰尘", "author": "XiaoXi"} ] }}
This is the REACT code
It should be because when the first render is initialized the asynchronous data is returned before the listdata is undefined, giving an initial value [].
Did you see the error message? Cannot read property 'map' of undefined
the object you call map is undefined, not map is undefined
This is the state when the component is initialized.
{ data: []}
Then you give ContentList
the listData
value of the property is this.state.data.listData
, this time Ajax has not returned data, listData must be undefined