最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React Native error: undefined is not an object (evaluating 'Object.keys(dataBlob[sectionID])') - St

programmeradmin2浏览0评论

I'm trying to display facebook page status in React Native application with facebook API in a ListView. This tutorial helpd me a lot and I managed to display the last status in my application.

But when I tried to put all the status in the ListView I get this error message : "undefined is not an object(evaluating 'Object.keys(dataBlob[sectionID])')"

I read in another stackoverflow post that it was because I tried to run cloneWithRows() function on an object instead of an Array. But I still can't manage to get over this error.

So if someone can help me that would be great. Here is a sample of the JSON generated by facebook API

{"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"},

And this is some of my index.ios.js file :

    constructor(props){
    super(props);
    this.state = {
      dataSource: new ListView.DataSource({
        rowHasChanged: (row1, row2) => row1 !== row2,
      }),
      loaded: false,
    };
  }

  ponentDidMount(){
    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}
      />
    );

In this line :

dataSource: this.state.dataSource.cloneWithRows(responseData.timeline),

I tried to replace 'timeline' with 'data' but that don't load the data and keep on LoadingView.

If you need more code or information let me know.

Thank you for your help.

I'm trying to display facebook page status in React Native application with facebook API in a ListView. This tutorial helpd me a lot and I managed to display the last status in my application.

But when I tried to put all the status in the ListView I get this error message : "undefined is not an object(evaluating 'Object.keys(dataBlob[sectionID])')"

I read in another stackoverflow post that it was because I tried to run cloneWithRows() function on an object instead of an Array. But I still can't manage to get over this error.

So if someone can help me that would be great. Here is a sample of the JSON generated by facebook API

{"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"},

And this is some of my index.ios.js file :

    constructor(props){
    super(props);
    this.state = {
      dataSource: new ListView.DataSource({
        rowHasChanged: (row1, row2) => row1 !== row2,
      }),
      loaded: false,
    };
  }

  ponentDidMount(){
    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}
      />
    );

In this line :

dataSource: this.state.dataSource.cloneWithRows(responseData.timeline),

I tried to replace 'timeline' with 'data' but that don't load the data and keep on LoadingView.

If you need more code or information let me know.

Thank you for your help.

Share Improve this question asked May 31, 2016 at 13:43 G.SabathierG.Sabathier 3771 gold badge4 silver badges13 bronze badges 2
  • What exactly is in responseData.timeline? Or for that matter responseData itself? – Tom Walters Commented May 31, 2016 at 13:53
  • @TomWalters I used responseData.timeline because i followed the tutorial I mensionned previously but normally it contain the data get with the fetch call to my facebook API. – G.Sabathier Commented May 31, 2016 at 14:00
Add a ment  | 

1 Answer 1

Reset to default 4

I finally found out what was wrong with my code. The error came from render function when I check if this.stat.timelines is set. But in this case 'timelines' doesn't exist.

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

This is how I fixed it.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论