2

我需要为固定数据表实现无限滚动功能。我检查了 API 文档,当用户滚动到表格末尾时没有调度事件。唯一看似有用的事件是 onScrollEnd,但该事件让我返回了 scrollX 和 scrollY。ScrollY 非常大,我不知道如何使用这个数字来检测用户是否在接近尾端滚动。谁能告诉我如何使用固定数据表实现无限滚动功能?谢谢

4

1 回答 1

0

It is a shame that such component does not have proper API for infinite scroll. The solution is this (but it is ugly):

The onScrollEnd() returns you a scrollY value. You need to persist this value in component state, e.g. this.state.scroll. On each onScrollEnd, you have to check for equality:

this.state.scroll === nextState.scroll && nextState.scroll !== 0 // you dont want to load dada on scrollTop.

If this is true, then you can load additional data, update your store or what you have, and re-render the component.

BIG PROBLEM: the onScrollEnd() function is very very slow :( Maybe do debouncing/throttling?

于 2017-01-04T10:07:06.037 回答