本文轉自 http://www.jb51.net/article/98558.htm
index.wxml代碼如下
http://www.jb51.net/article/98558.htm
//后台返回數據渲染
<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}}" catchtap="setLoading"> {{loadText}} </button> </view>
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, }) } }) } })