当然不会! 这是因为名字是一个空数组!
解决方案:
1-此添加到类,然后从文件的顶部除去名称,图像,和概要:
constructor(props){
super(props)
this.state = {
names : [],
images : [],
summaries : []
}
}
2-呼叫在构造获取数据并将其取出从渲染方法(你应该这样做,调用渲染内渲染,你会最终有一个无限循环的任何东西!):
constructor(props){
super(props)
this.state = {
names : [],
images : [],
summaries : []
}
let that = this
fetch(topFifty).then(function(response) {
return response.json().then(function(json) {
let names = [], images = [], summaries = []
json.feed.entry.forEach(function(datum) {
names.push(datum["im:name"].label)
images.push(datum["im:image"][0].label)
summaries.push(datum.summary.label)
})
that.setState({names:names,
images: images,
summaries: summaries})
})
})
}
嗯,返回'类型错误:未定义无法读取属性“的setState” '有没有ab我可以管理国家吗? –
确定修正,请注意将this.setState替换为that.setState,并添加let that this .... – challenger