A有问题 我需要实现行星名称和角色的输出 实现了行星名称的推导 在派生字符时,链接到API,但您需要他们的名字 如何结合这一切? 非常感谢您提前
这是我的代码
<!DOCTYPE html>
<title>Simple markers</title>
<div id="map-canvas"></div>
<script type="text/javascript">
function getStarWarsPlanets(progress, url = 'https://swapi.co/api/planets', planets = []) {
return new Promise((resolve, reject) => fetch(url)
.then(response => {
if (response.status !== 200) {
throw `${response.status}: ${response.statusText}`;
}
response.json().then(data => {
planets = planets.concat(data.results);
if(data.next) {
progress && progress(planets);
getStarWarsPlanets(progress, data.next, planets).then(resolve).catch(reject)
} else {
resolve(planets);
}
}).catch(reject);
}).catch(reject));
}
function progressCallback(planets) {
}
getStarWarsPlanets(progressCallback)
.then(planets => {
document.writeln(planets.map(p => p.name))
document.writeln(planets.map(p => p.residents))
})
.catch(console.error);
</script>
&#13;