我试图在ListView中的Facebook API中显示React Native应用程序中的Facebook页面状态。 This tutorial帮了我很多,我设法在我的应用程序中显示最后一个状态。React本机错误:undefined不是一个对象(评估'Object.keys(dataBlob [sectionID])')
但是,当我试图把所有的状态在ListView我得到这个错误信息:“未定义是不是(评估‘Object.keys(dataBlob [sectionID])’)的对象”
我读另一个stackoverflow后,这是因为我试图 运行cloneWithRows()函数对象而不是一个数组。但我仍然无法克服这个错误。
所以,如果有人能帮助我,这将是伟大的。下面是Facebook的API生成的JSON的样品
{"data":[{"message":"Test","created_time":"2016-05-31T13:36:56+0000","id":"1602039116775292_1605827029729834"},
{"message":"Hello","created_time":"2016-05-31T13:36:50+0000","id":"1602039116775292_1605827006396503"},
这是我的一些index.ios.js文件:
constructor(props){
super(props);
this.state = {
dataSource: new ListView.DataSource({
rowHasChanged: (row1, row2) => row1 !== row2,
}),
loaded: false,
};
}
componentDidMount(){
this.fetchData();
}
fetchData(){
fetch(REQUEST_URL)
.then((response) => response.json())
.then((responseData) => {
this.setState({
dataSource: this.state.dataSource.cloneWithRows(responseData.timeline), //The problem is here
loaded: true,
});
})
.done();
}
render(){
if (!this.state.timelines) {
return this.renderLoadingView();
}
return(
<ListView
dataSource={this.state.dataSource}
renderRow={this.renderStatus}
style={styles.listView}
/>
);
在这一行:
dataSource: this.state.dataSource.cloneWithRows(responseData.timeline),
我尝试用'data'替换'时间线',但不加载数据并保留在LoadingView中。
如果您需要更多的代码或信息,请告诉我。
谢谢你的帮助。
“responseData.timeline”究竟是什么?或者就此而言'responseData'本身? –
@TomWalters我使用了responseData.timeline,因为我遵循之前提到的教程,但通常它包含获取调用到我的Facebook API的数据。 –