响应中的地图函数(错误:TypeError:e.map不是函数)

问题描述:

我想从道具中渲染物品,我可以使用初始状态来实现,但不能通过服务器的响应来实现.我的渲染功能:

I want to render items from props, I can do it with initial state, but not with response from server. My render function :

 const { data } = this.props;
    return (
      <div >
          {data.map((item, index) =>
              <div key={index} className="row">
                  <span data = { data } className="number col-4 col-md-8">{item._id}</span>
                  <span data = { data } className="date col-4 col-md-2">{item.date}</span>
                  <span data = { data }  className="tag col-4 col-md-2">{item.tag}</span>
                  <div className="col-md-12 ">
                    {item.text}
                  </div>                
              </div>
          )}
      </div>
    )
  }

我遇到这个错误:

TypeError:e.map不是函数

TypeError: e.map is not a function

响应:对象{数据:数组(12),状态:200,状态文本:确定",标头:对象,配置:对象…}

response : Object {data: Array(12), status: 200, statusText: "OK", headers: Object, config: Object…}

必须更改父组件才能对此进行更改:

Had to change parent component change this:

  this.setState({
    data: response
  })

  this.setState({
    data: response.data
  })

我试图从子组件中获取数据,但是它不起作用(可能是由于map功能)

I've tried to reach the data from the child component, but it din't work (probably because of the map function)