【发布时间】:2021-05-12 15:48:21
【问题描述】:
作为一个初学者项目,我正在制作一个简单的应用程序来跟踪国际空间站。我正在调用一个 API,在浏览器上我看到返回了多行,而不仅仅是我想要的那一行(纬度和经度)。
这是我正在使用的 API:
{
message: "success",
timestamp: 1612832513,
iss_position: {
longitude: "-112.2064",
latitude: "35.1744"
}
}
这是我认为问题所在的代码部分:
render() {
var { items, isLoaded } = this.state;
if (!isLoaded) {
return <div>Loading...</div>;
} else {
return (
<div>
<ul>
{Object.values(items).map(item => (
<li key={item}>
<span >Latitude: {item.latitude} </span>
<span >Longitude: {item.longitude} </span>
</li>
))}
</ul>
</div>
)
};
};
这是我在浏览器中看到的:
Latitude: Longitude:
Latitude: Longitude:
Latitude: -45.0969 Longitude: -32.9972
我认为问题出在.map(),但不知道该怎么做。任何帮助,将不胜感激。另外,如果我遗漏了任何我应该包含的信息,请告诉我,我会更新它。
【问题讨论】:
标签: reactjs api dictionary object