【问题标题】:react native .then(() => {反应原生 .then(() => {
【发布时间】:2018-12-07 09:06:11
【问题描述】:

我想在 React Native 中的 ListView 中实现 Pull-to-Refresh。

...

_onRefresh() {
        this.setState({refreshing: true});
        this._refreshData(this.course).then(() => {
          this.setState({refreshing: false});
        });
      }

....

_refreshData(course) {
    this.props.dispatch(clearLectures());
    this.props.dispatch(fetchLectures(course));
  }

....

  return (

          <ListView
            dataSource={dataSource.cloneWithRowsAndSections(lectures)}
            renderRow={this._renderRow}
            renderSectionHeader={this._renderDayHeader}

            refreshControl={
              <RefreshControl
              refreshing={this.state.refreshing}
              onRefresh={this._onRefresh.bind(this)}
              />
            }

          />

    );

....

我收到以下错误:无法读取未定义的属性 'then'。

我必须在 _refreshData 函数中实现某种返回还是另一个问题?

【问题讨论】:

  • 使您的 _refreshData 函数异步,以便它可以返回承诺

标签: listview react-native pull-to-refresh


【解决方案1】:

当错误是“无法读取未定义的属性'property_name'”时,您需要做的是了解什么是未定义的?

所以你正在做的是类似于“this.undefined.then”的东西。

this._refreshData 不返回任何内容,因此您在未定义时调用 then。 this._refreshData 应该返回作为属性的东西:我认为你需要返回一个 Promise。

类似:

_refreshData(course) {
    return new Promise((resolve, reject) => {
        //get data
        // resolve(data) or reject(error)
    }
}

我不知道你是如何实现你的商店和你的组件的,所以我不能多说。

也许这个link 可以帮助你。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 2021-11-07
    • 2021-05-03
    • 2018-03-30
    • 2017-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多