zoukankan      html  css  js  c++  java
  • 小程序之列表分页加载

    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;
            }
            
        }
  • 相关阅读:
    17款加速效率的CSS工具
    我为什么向后端工程师推荐Node.js
    八款开源 Android 游戏引擎 (巨好的资源)
    50个必备的实用jQuery代码段
    $.getJSON()跨域请求
    javascript獲得服務器端控件的ID
    (转)8款在线CSS优化工具/组织和压缩CSS
    10 个文件和文档的比较工具
    40个有创意的jQuery图片和内容滑动及弹出插件收藏集之四
    MBP换硬盘的过程
  • 原文地址:https://www.cnblogs.com/wanan-01/p/9077999.html
Copyright © 2011-2022 走看看