微信小程序加载更多,点击查看更多

微信小程序加载更多,是将之前的数据和点击加载后请求的数据用concat拼接在一起并执行setData,

下面是一个简单的栗子:

index.wxml代码如下

<view wx:for="{{duanziInfo}}" wx:for-item="name" wx:for-index="id"> 
    <view class="duanzi-view">
      <view class="duanzi-content">
        <text class="dz-content">{{name.content}}</text>
      </view>
    </view>
</view>
<view class="button-wrapper">
  <button type="default" size="default" loading="{{loading}}" disabled="{{disabled}}" bindtap="setLoading">
    {{loadText}}
  </button>
</view>
加载更多按钮绑定setLoading

index.js文件代码如下

Page({
        data: {
            loadText:'加载更多',
            duanziInfo:[]
        },
	//初始化请求
	onLoad: function (res) {
		var that = this
		//内容
		wx.request({
			url: 'http://xxxxx.com/index.php?m=Industry&a=getDuanziInfo',
			data: {token:token},
			method: 'GET', 
			success: function(res){
			console.log(res.data.result) //打印初始化数据
				that.setData({
				duanziInfo:res.data.result
				})
			}
		})
	  },
	  //加载更多
	setLoading: function(e) {
		var duanziInfoBefore = this.data.duanziInfo
		var that = this
		wx.showToast({ //期间为了显示效果可以添加一个过度的弹出框提示“加载中”
			title: '加载中',
			icon: 'loading',
			duration: 200
		  })
		wx.request({
			url: 'http://xxxxx.com/index.php?m=Industry&a=getDuanziInfo',
			data: {token:token},
			method: 'GET', 
			success: function(res){
				console.log(duanziInfoBefore.concat(res.data.result)) //打印拼接之后数据
			    that.setData({
				loadText:"数据请求中",
				loading:true,
				duanziInfo:duanziInfoBefore.concat(res.data.result),
				loadText:"加载更多",
				loading:false,
			  })
			}
		})
	}
})

初始化和加载更多中的打印数据如下


(以上是点击查看更多,还可以根据距离视图区域的距离来加载更多,具体实现是将视图用<scroll-view>标签,并给其一个固定高度,在给定参数中设置距离像素触发事件。具体文档:https://mp.weixin.qq.com/debug/wxadoc/dev/component/scroll-view.html?t=20161122)


  • 3
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值