【发布时间】:2019-10-09 16:51:55
【问题描述】:
我正在使用 Finding Advanced API 成功地从 eBay 查询数据。我正在映射要在页面上显示的项目。我可以显示查询项目的标题和图像。但是,当我尝试降低嵌套在数组中的价格时,我遇到了麻烦。
数据如下:
{
itemId: [
"120901386991"
],
title: [
"1952 Topps Mickey Mantle Chase Card Box 18 packs 5 1950s or 1960's cards per box"
],
globalId: [
"EBAY-US"
],
subtitle: [
"3 BX LOT. 1 VINTAGE PK PER 25 BOXES* LOOK 4 1952 MANTLE"
],
primaryCategory: [
{
categoryId: [
"213"
],
categoryName: [
"Baseball Cards"
]
}
],
secondaryCategory: [
{
categoryId: [
"156521"
],
categoryName: [
"Vintage Non-Sport Cards"
]
}
],
galleryURL: [
"https://thumbs4.ebaystatic.com/m/m1mtMB65mAApWQ2EhJy4qWA/140.jpg"
],
viewItemURL: [
"https://rover.ebay.com/rover/1/711-53200-19255-0/1?ff3=2&toolid=10044&campid=5338164673&customid=watchbask&lgeo=1&vectorid=229466&item=120901386991"
],
paymentMethod: [
"PayPal"
],
autoPay: [
"true"
],
location: [
"USA"
],
country: [
"US"
],
shippingInfo: [
{
shippingServiceCost: [
{
@currencyId: "USD",
__value__: "0.0"
}
],
shippingType: [
"Free"
],
shipToLocations: [
"Worldwide"
],
expeditedShipping: [
"false"
],
oneDayShippingAvailable: [
"false"
],
handlingTime: [
"1"
]
}
],
sellingStatus: [
{
currentPrice: [
{
@currencyId: "USD",
__value__: "118.0"
}
],
convertedCurrentPrice: [
{
@currencyId: "USD",
__value__: "118.0"
}
],
sellingState: [
"Active"
],
timeLeft: [
"P13DT19H16M11S"
]
}
],
listingInfo: [
{
bestOfferEnabled: [
"false"
],
buyItNowAvailable: [
"false"
],
startTime: [
"2012-04-23T16:52:17.000Z"
],
endTime: [
"2019-10-23T16:52:17.000Z"
],
listingType: [
"FixedPrice"
],
gift: [
"false"
],
watchCount: [
"444"
]
}
],
returnsAccepted: [
"false"
],
condition: [
{
conditionId: [
"1000"
],
conditionDisplayName: [
"Brand New"
]
}
],
isMultiVariationListing: [
"false"
],
pictureURLLarge: [
"https://i.ebayimg.com/00/s/NTAwWDMxNA==/z/sT8AAOSw62VZv9qQ/$_1.JPG"
],
topRatedListing: [
"false"
]
},
我使用“卡片”表示法传递道具,即 ebay 项目。我也可以在谷歌开发工具中看到道具。
因此,虽然我可以成功显示标题,但在反应中使用 {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} />
我在这里错过了什么吗?
【问题讨论】:
-
你确定 sellStatus 是一个数组吗?在这里,它看起来是一个对象。 developer.ebay.com/DevZone/finding/CallRef/Samples/…
-
这是我从 api pastebin.com/mqCscKss得到的输出
-
我无法访问 pastebin,你能补充一下问题吗?
-
好的,我发布到我的问题开始
-
几乎所有东西似乎都在一个数组中,有趣的 api 响应。