Javascript-react get Array data when encountered cannot read property ' map ' of undefined

Source: Internet
Author: User
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

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.