【发布时间】:2017-04-23 04:42:37
【问题描述】:
根据documentation,ListView 的 onLoadMore() 回调只应在“ListView 一直滚动到第一页底部”时触发。
我确实有以下实现,问题是即使不向下滚动页面,ListView 也不会停止调用 onLoadMore 回调。这不是一个可接受的解决方案,因为它只是在视图打开一段时间后加载了太多数据,以至于没有响应。
代码如下所示:
<ListView
data={this.state.posts}
renderRow={this.renderRow}
loading={this.state.loading}
onLoadMore={this.onFeedLoadMore}
/>
...
onFeedLoadMore() {
console.log("onFeedLoadMore called");
this.setState({loading: true});
if (_.has(this.state.paging, 'next')) {
fetch(this.state.paging.next, {
method: 'GET',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
}
}).then((response) => response.json()).then((responseJson) => {
this.setState({loading: false});
console.log(responseJson);
this.setState({paging: responseJson.paging});
this.setState({posts: this.state.posts.concat(responseJson.data)})
}).catch((error) => {
this.setState({loading: false});
console.log("error fetching paged fb newsfeed: ", error);
})
}
}
【问题讨论】:
标签: react-native shoutem