【发布时间】:2021-09-24 21:09:20
【问题描述】:
我有这个来自 api 的数组数据,我想使用 map 函数在 react tsx 文件中制作它
{
"data":{
"cart":{
"1":{
"product_id":1,
"name":"Product 1",
"quantity":1,
"price":"1.00"
},
"2":{
"product_id":2,
"name":"Product 2",
"quantity":1,
"price":"1.00"
}
}
}
}
React Typescript 代码(但不工作):
(data.cart.map((item:any, key:any) => (
<p>{item.product_id}</p>
<p>{item.name}</p>
<p>{item.quantity}</p>
<p>{item.price}</p>
)))
我想修复 react tsx 代码
【问题讨论】:
-
你的错误信息是什么?
-
控制台日志:TypeError: e.map is not a function
标签: arrays reactjs typescript react-tsx