Page({ data: { current_address: "", wc_guide_info:[], current_page:1, //當前頁碼 sum_page:1 //總頁碼,后台會返回 }, getwcinfo: function (){ var that=this; wx.showLoading({ title: '加載中', }) wx.request({ url: app.globalData.url + 'index.php/api/Home/index', data:{ type:1, lng: app.globalData.location.longitude, lat: app.globalData.location.latitude, page: that.data.current_page, page_size:8 //每頁加載的數據,建議數字大一點,數字小了第一頁數據沒有到底部,不足以觸發onReachBottom函數,不能加載第二頁數據 }, success:function(data){ wx.hideLoading(); if (data.data.status==200){ if (that.data.current_page==1){ that.setData({ wc_guide_info: data.data.data.res, sum_page: data.data.data.totalpage }) }else{ var new_page_cont = that.data.wc_guide_info; var current_guide_list = data.data.data.res; for (var i = 0; i < current_guide_list.length;i++){ new_page_cont.push(current_guide_list[i]) } that.setData({ wc_guide_info: new_page_cont }) } }else{ wx.showToast({ title: data.data.error, icon: 'loading', duration: 1000 }); } }, fail:function(){ wx.hideLoading(); wx.showToast({ title: '請求失敗', icon:'loading', duration:1000 }) } }) }, onReachBottom: function (e){ var that=this; var current_page=null; current_page = that.data.current_page+1; that.setData({ current_page: current_page }) if (current_page <= that.data.sum_page){ wx.showToast({ title: '加載中!', icon: 'loading', duration:1000 }) that.getwcinfo(); } else if (current_page > that.data.sum_page){ wx.showToast({ title: '數據已加載完', icon: 'loading', duration: 1000 }); return; } }