最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

怎样使用ReactnativeListView增加顶部下拉刷新和底下点击刷新

来源:动视网 责编:小采 时间:2020-11-27 19:42:14
文档

怎样使用ReactnativeListView增加顶部下拉刷新和底下点击刷新

怎样使用ReactnativeListView增加顶部下拉刷新和底下点击刷新:这次给大家带来怎样使用React native ListView增加顶部下拉刷新和底下点击刷新,使用React native ListView增加顶部下拉刷新和底下点击刷新的注意事项有哪些,下面就是实战案例,一起来看一下。1. 底部点击刷新1.1 先增加一个按钮 render() {
推荐度:
导读怎样使用ReactnativeListView增加顶部下拉刷新和底下点击刷新:这次给大家带来怎样使用React native ListView增加顶部下拉刷新和底下点击刷新,使用React native ListView增加顶部下拉刷新和底下点击刷新的注意事项有哪些,下面就是实战案例,一起来看一下。1. 底部点击刷新1.1 先增加一个按钮 render() {
 这次给大家带来怎样使用React native ListView增加顶部下拉刷新和底下点击刷新,使用React native ListView增加顶部下拉刷新和底下点击刷新的注意事项有哪些,下面就是实战案例,一起来看一下。

1. 底部点击刷新

1.1 先增加一个按钮

render() {
 if(!this.state.data){
 return(
 <Text>Loading... </Text>
 )
 }else{
 return(
 <ListView
 refreshControl={
 <RefreshControl 
 refreshing = {false}
 onRefresh = {this.reloadWordData.bind(this)}
 />
 }
 dataSource={this.state.data}
 renderRow={(rowData)=>this.renderRow(rowData)}
 renderFooter={this.renderFooter.bind(this)}
 >
 </ListView>
 
 );
 }
 }
 
renderFooter(){
 return (
 <View style={{marginVertical: 10, marginBottom:20}} >
 <Button
 onPress={this.addMoreOnFoot.bind(this)}
 title="点击载入更多"
 />
 </View>
 )
 }

给ListView 增加一个renderFooter 方法来绘制底部元素。在里面显示一个按钮。

按钮处理逻辑:

addMoreOnFoot(){
 // alert('addMoreOnFoot')
 // console.log('addMoreOnFoot')
 const url = 'http://127.0.0.1/getFootContent?lastid=' + this.state.footLastId + '&count=20&isTop=0'
 fetch(url)
 .then((response)=>response.json())
 .then((jsondata)=>{
 if (jsondata.data && jsondata.data.length > 0){
 const rowData = this.state.jsondata.concat(jsondata.data);
 this.setState({
 footLastId:jsondata.data[jsondata.data.length - 1]['id'],
 jsondata:rowData,
 data:new ListView.DataSource({rowHasChanged:(r1, r2) => r1 != r2}).cloneWithRows(rowData),
 })
 }
 })
 .catch((error)=>{
 alert(error);
 });
}

点击后进行网络处理,把之前最后一条id也传给服务器,让服务器返回这个id后面的20条记录。然后重新setState即可。

2. 头部下拉刷新

ListView中增加RefeshControl

render() {
 if(!this.state.data){
 return(
 <Text>Loading... </Text>
 )
 }else{
 return(
 
 <ListView
 refreshControl={
 <RefreshControl 
 refreshing = {false}
 onRefresh = {this.reloadWordData.bind(this)}
 />
 }
 dataSource={this.state.data}
 renderRow={(rowData)=>this.renderRow(rowData)}
 renderFooter={this.renderFooter.bind(this)}
 >
 </ListView>
 
 );
 }
 }

载入最新的头部数据添加到this.State中

reloadWordData(){
 // alert(this.state.topLastId)
 const url = 'http://127.0.0.1/getFootContent?lastid=' + this.state.topLastId + '&count=20&isTop=1'
 fetch(url)
 .then((response)=>response.json())
 .then((jsondata)=>{
 if (jsondata.data && jsondata.data.length > 0){
 const rowData = jsondata.data.concat(this.state.jsondata);
 this.setState({
 topLastId:jsondata.data[0]['id'],
 jsondata:rowData,
 data:new ListView.DataSource({rowHasChanged:(r1, r2) => r1 != r2}).cloneWithRows(rowData),
 })
 }
 })
 .catch((error)=>{
 alert(error);
 });
 }

相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!

推荐阅读:

如何使用vue.extend实现alert模态框弹窗组件

如何使用vue组件实现弹出框点击显示隐藏

文档

怎样使用ReactnativeListView增加顶部下拉刷新和底下点击刷新

怎样使用ReactnativeListView增加顶部下拉刷新和底下点击刷新:这次给大家带来怎样使用React native ListView增加顶部下拉刷新和底下点击刷新,使用React native ListView增加顶部下拉刷新和底下点击刷新的注意事项有哪些,下面就是实战案例,一起来看一下。1. 底部点击刷新1.1 先增加一个按钮 render() {
推荐度:
标签: 刷新 React listview
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top