今天被這個問題搞得頭疼,寫一個分頁加載,但是listview的onEndReached方法老是被頻繁調用,知道加載完所有的分頁數據才停止。
<ListView automaticallyAdjustContentInsets = {false} contentOffset = {{x:0,y:0}} enableEmptySections={true} dataSource={this.state.dataSourceModel} renderRow={this.renderRowModel.bind(this)} pageSize={10} initialListSize={20} onEndReached={this.loadModeDataMore()} onEndReachedThreshold={10} >
這是代碼,后來問過ios的同事才明白,
把 onEndReached={this.loadModeDataMore()}改為onEndReached={()=>this.loadModeDataMore()}就好了,
因為是要把這個方法當做參數傳進去,如果不加'()=>'
onEndReached就會把你當成每次都需要執行的一個方法,就會導致頻繁調用。