我是新的,仍然在探索在React JS中显示和映射数据.
我想显示嵌套的数据数组对象,但它的行为是我想要的. 以下是数据:
{
name: {},
tld: [],
subregion: "Western Europe",
languages: {
fra: "French",
gsw: "Swiss German",
ita: "Italian",
roh: "Romansh"
},
我也想显示语言对象数据,但它总是返回一个错误.
下面是我如何try 观察数据行为的代码块:
console.log(countries)
countries.map(country => {
console.log('Name:', country.name.common)
console.log('Area:', country.area),
console.log('Language:', country.languages)
// Object.keys(country.languages).map((language) => {
// console.log(language)
// })
});
我试着使用Object.keys,但它也返回了一个错误 ShowCountry. jsx:7 Uncaught TypeError:Cannot convert undefined or null to object
我还try 使用.map()
{countries.map(country => (
<div>
<p>Country: {country.name.common}</p>
<p>Area: {country.area}</p>
<h3>Languages</h3>
<ul>
{/* {country.languages.map((language) => (
<li>{language}</li>
))ther
} */}
</ul>
</div>
))
}
它返回一个错误,www.example.com不是一个函数,我怀疑它可能是null或空的.这个方法是我通常在Stackoverflow问题中看到的,它应该工作,但我注意到语言是一个对象语言:{...}而其他问题是数组对象,如array:[{...},{...}].
我认为这个问题很容易,但我搞不懂这个问题.你能帮我一下吗,也给一点解释或相关链接.