我正在尝试从React组件中的API获取数据
{this.props.buyer && this.props.buyer[0].phone_number[0].number}
-引发错误
无法读取未定义的属性'number'
{this.props.buyer && this.props.buyer[0].name}
-运行正常
这是API数据
Orders: {
buyer:
},
}
[
{
"id": 2,
"name": "Qi Xiang",
"type": "Consignee",
"address": {
"id": 2,
"type": "shipping",
"street": "China China",
"city": "Beijing",
"postal_code": "34343",
"province": "23232",
"country": "CN"
},
"email": null,
"phone_number": {
"number": "323232",
"type": "Phone"
},
"id_image_url": "/api/files/24e49645-df42-4984-a
}
]
},
}
答案 0 :(得分:0)
您的phonenumber
不是数组。您必须使用此:
this.props.buyer[0].phone_number.number