【发布时间】:2021-04-24 18:24:46
【问题描述】:
这是我的 API,我想使用 axios 获取它
[
{
"groupType": "Interessegruppe",
"groups": [
{
"id": "c42b0250-375e-4458-8f68-0df8179f889c",
"name": "Teater",
"assignmentStrategy": 1
},
{
"id": "0fb94732-2bb1-483b-abbd-858327339ca0",
"name": "Fotball",
"assignmentStrategy": 1
},
{
"id": "6b109ab1-5a3e-46b0-b0cc-e2b48d6e2dc6",
"name": "Foto",
"assignmentStrategy": 1
}
]
},
]
我写了那个代码
renderItem={({ item }) => <GroupCard title={item.groupType} subTitle={item.groups.name} />}
/>
我获取了 groupType,但我无法获取任何 [id 或 name]
【问题讨论】:
-
item.groups是一个数组,所以你需要使用list rendering(没有item.groups.name,但是有item.groups[0].name例子)
标签: javascript arrays react-native api axios