商品列表的显示问题
来源:10-3 订单详情的开发

慕粉2159227552
2019-06-02
请问老师:
将接口中传递过来的商品列表加载到页面中时使用如下语句缓存
let productList = this.state.orderInfo.orderItemVoList || [];
然后对productList使用map方法没有问题
productList.map((product, index) => ...
但是直接使用
this.state.orderInfo.orderItemVoList.map((product, index) => ...
会报错是为什么
写回答
2回答
-
可以打印下productList,看看是什么结果。再就是报的什么错误?
032019-06-13 -
慕粉2159227552
提问者
2019-06-13
原因是在componentDidMount之前先执行了render函数,此时的
this.state.orderInfo.orderItemVoList中还是undefined,因此不是数组无法使用map函数。在挂载完成之后调用this.loadOrderDetail()。这时才得到从接口传来的数据。
00
相似问题