gpt4 book ai didi

javascript - react native 错误 : undefined is not an object (evaluating 'Object.keys(dataBlob[sectionID])' )

转载 作者:可可西里 更新时间:2023-11-01 05:40:20 27 4
gpt4 key购买 nike

我正在尝试使用 ListView 中的 facebook API 在 React Native 应用程序中显示 facebook 页面状态。 This tutorial帮了我很多,我设法在我的应用程序中显示了最后的状态。

但是当我尝试将所有状态放入 ListView 时,我收到此错误消息:“undefined is not an object(evaluating '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),

我尝试用“数据”替换“时间线”,但不会加载数据并继续使用 LoadingView。

如果您需要更多代码或信息,请告诉我。

感谢您的帮助。

最佳答案

我终于发现我的代码出了什么问题。当我检查是否设置了 this.stat.timelines 时,错误来自渲染函数。但在这种情况下,“时间线”并不存在。

if (!this.state.loaded) {
return this.renderLoadingView();
}

我就是这样解决的。

关于javascript - react native 错误 : undefined is not an object (evaluating 'Object.keys(dataBlob[sectionID])' ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37547503/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com