Reactjs 如何访问api对象内部的键

Reactjs 如何访问api对象内部的键,reactjs,rest,api,Reactjs,Rest,Api,我正试图从API中选择一个选项来获取国家/地区 github链接: 它过去像过去两天一样工作,但现在我只是在选择选项中获取数字,而不是国家。 我应该如何访问国家,以便在选择选项标签上显示 const respCountries = await Axios.get("https://covid19.mathdro.id/api/countries"); const countries = Object.keys(respCountries.data.countries); this.

我正试图从API中选择一个选项来获取国家/地区

github链接:

它过去像过去两天一样工作,但现在我只是在选择选项中获取数字,而不是国家。 我应该如何访问国家,以便在选择选项标签上显示

  const respCountries = await Axios.get("https://covid19.mathdro.id/api/countries");
  const countries = Object.keys(respCountries.data.countries);
  this.setState({
    confirmed: respApi.data.confirmed.value,
    recovered: respApi.data.recovered.value,
    deaths: respApi.data.deaths.value,
    countries
  });
}

renderCountryOptions(){
  return this.state.countries.map((country,i)=>{
      return <option key={i}>{country}</option>
  });
}



const resp countries=wait Axios.get(“https://covid19.mathdro.id/api/countries");
const countries=Object.key(respCountries.data.countries);
这是我的国家({
确认:respApi.data.confirmed.value,
已恢复:respApi.data.recovered.value,
死亡:respApi.data.death.value,
国家
});
}
renderCountryOptions(){
返回此.state.countries.map((国家,i)=>{
返回{country}
});
}

{country.name}国家现在是一个具有其他属性的对象

{country.name}国家现在是具有其他属性的对象

删除
对象。键
,这是不必要的,并且您的国家/地区更新状态不正确

const countries = respCountries.data.countries;

this.setState({
    confirmed: respApi.data.confirmed.value,
    recovered: respApi.data.recovered.value,
    deaths: respApi.data.deaths.value,
    countries: countries,
  });

renderCountryOptions(){
  return this.state.countries.map((country,i)=>{
      return <option key={i}>{country.name}</option>
  });
}
const countries=respCountries.data.countries;
这是我的国家({
确认:respApi.data.confirmed.value,
已恢复:respApi.data.recovered.value,
死亡:respApi.data.death.value,
国家:国家,,
});
renderCountryOptions(){
返回此.state.countries.map((国家,i)=>{
返回{country.name}
});
}

删除
对象。键
,它是不必要的,并且您的国家/地区更新状态不正确

const countries = respCountries.data.countries;

this.setState({
    confirmed: respApi.data.confirmed.value,
    recovered: respApi.data.recovered.value,
    deaths: respApi.data.deaths.value,
    countries: countries,
  });

renderCountryOptions(){
  return this.state.countries.map((country,i)=>{
      return <option key={i}>{country.name}</option>
  });
}
const countries=respCountries.data.countries;
这是我的国家({
确认:respApi.data.confirmed.value,
已恢复:respApi.data.recovered.value,
死亡:respApi.data.death.value,
国家:国家,,
});
renderCountryOptions(){
返回此.state.countries.map((国家,i)=>{
返回{country.name}
});
}

它抛出一个错误类型错误:无法读取未定义项的属性“map”在此处正常工作我发现您的国家/地区设置状态不正确,我更新了答案,您可以重试@NitinIt抛出一个错误类型错误:无法读取未定义项的属性“map”在此处正常工作我发现您的国家/地区设置状态不正确,我更新了答案,你可以再试一次@Nitin