无法使用Ebay在React中找到高级API来显示价格数据
我正在使用Finding Advanced API从eBay成功查询数据。我正在映射要显示在页面上的项目。我可以显示所查询项目的标题和图像。但是,当我尝试降低嵌套在数组中的价格时遇到了麻烦。
数据看起来像这样:
sellingStatus: [
{
currentPrice: [
{
@currencyId: "USD",
__value__: "118.0"
}
],
convertedCurrentPrice: [
{
@currencyId: "USD",
__value__: "118.0"
}
],
sellingState: [
"Active"
],
timeLeft: [
"P14DT0H20M10S"
]
}
],
我已经使用“卡片”符号(即ebay物品)传递了道具。我也可以在Google开发工具中看到道具。
因此,我可以在反应中使用{card.title}
成功显示标题
当我使用{card.sellingStatus.convertedCurrentPrice}
时出现此错误:
TypeError:无法读取未定义的属性'convertedCurrentPrice'
我尝试了其他一些变体,但似乎没有任何效果。
注意,这是我要显示的“卡”组件(此代码显示了我用于价格的另一种选择。
const Card = props => {
const { card } = props;
return (
<div className="col-md-3">
<div className="card">
<div className="card-block">
{/* <h5 className="card-title">{card.title}</h5> */}
<div className="mx-auto" style={{ width: 200 }}>
<img
src={card.pictureURLLarge}
style={{
width: 190,
height: 200
}}
className="img-responsive"
alt="..."
/>
</div>
<div className="card-body">
<h2>{card.sellingStatus.convertedCurrentPrice["__value__"]}</h2>
</div>
</div>
</div>
</div>
另外请注意,这是我的地图功能
{card_list.map(item => (
<Card key={item.id} card={item} />
我在这里想念什么吗?
回答如下:您可以看到sellingStatus是一个数组。因此您将必须映射或获得这样的值。
card.sellingStatus['convertedCurrentPrice]["__value__"]
或
card.sellingStatus[0].currentPrice[0]["__value__"];
因为您不需要多个<h2>