五味瓶

五味瓶

70飞吻 2017-9-27 加入 来自广州市

(好用,但就是感觉少了点什么)

五味瓶 最近的提问

五味瓶 最近的回答

  • 2018-5-16 16:50:46求layui分页的demo 分享,最好有数据的,文档的看了没很明白中回答:

    /**
    *分页
    *
    *@method layuiPage
    *
    * @param {[String]} type [请求类型(可选)] 如:"post"
    * @param {[String]} url [请求地址(必须)] 如:"/getData.do"
    * @param {[Object]} data [请求参数(可选)] 如:{"key":"value",...}
    * @param {[String]} dataType [数据类型(可选)] 如:'json'
    * @param {[String]} pageId [分页id(必须)] 如:"page"
    * @param {[Function]} beforeSend [请求前执行函数(可选)] 如:function(){}
    * @param {[Function]} success [请求成功后执行函数(必须)] 如:function(){}
    * @param {[Number]} pageSize [每页显示条数(可选)] 如:10
    * @param {[Number]} page [从哪条数据开始(可选)] 如:0
    * @param {[Array]} limits [每页条数规格(可选)] 如:[10, 20, 30, 50, 100]
    * @param {[Number]} groups [连续出现的页码个数(可选)] 如:5
    * @param {[Array]} layout [分页排版(可选)] 如:["count", "prev", "page", "next", "limit", "skip"]
    * @param {[String]} theme [自定义主题色(可选)] 如:"#1776f9"
    */
    jQuery.extend({
    layuiPage: function(obj){
    var type = obj.type || 'post',
    url = obj.url,
    data = obj.data || {},
    dataType = obj.dataType||'json',
    pageId = obj.pageId,
    beforeSend = obj.beforeSend || function() {},
    success = obj.success,
    limits = obj.limits || [10, 20, 30, 50, 100],
    groups = obj.groups || 5,
    layout = obj.layout || ['count', 'prev', 'page', 'next', 'limit', 'skip'],
    theme = obj.theme || '#1776f9';

    //每页显示条数
    data.pageSize = obj.pageSize||10;
    //每页从哪条数据开始,相当根据下标对数据截取
    data.page = obj.page||0;

    $.ajax({
    type: type,
    url: url,
    data: data,
    dataType: dataType,
    beforeSend: function(){
    beforeSend();
    },
    success: function(res){
    layui.laypage.render({
    elem: pageId,
    count: res.recordCount, //数据总条数
    limit: data.pageSize,
    limits: limits,
    groups: groups,
    first: '首页',
    last: '尾页',
    layout: layout,
    theme: theme,
    jump: function(o, first) {
    if(first){
    success(res);
    }else{
    data.pageSize = o.limit; //每页显示条数
    data.page = o.limit * (o.curr - 1); //当前页从0开始,需要减1
    $.layuiChangePage(url, data, beforeSend, success, type);
    }
    }
    });
    }
    });
    },
    layuiChangePage: function(url, data, beforeSend, success, type) {
    $.ajax({
    type: type,
    url: url,
    data: data,
    beforeSend: function() {
    beforeSend();
    },
    success: function(res) {
    var res = JSON.parse(res);
    success(res)
    }
    });

    }
    });


    //调用示范(参数在顶部有说明)
    $.layuiPage({
    url: "/baidu.do",
    data: field,
    pageId: "page1",
    beforeSend: function() {
    loadIndex = layer.load(1)
    },
    success: function(res) {
    layer.close(loadIndex);

    }
    });
  • 2018-5-16 16:46:33求layui分页的demo 分享,最好有数据的,文档的看了没很明白中回答:

    /**
    *分页
    *
    *@method layuiPage
    *
    * @param {[String]} type [请求类型(可选)] 如:"post"
    * @param {[String]} url [请求地址(必须)] 如:"/getData.do"
    * @param {[Object]} data [请求参数(可选)] 如:{"key":"value",...}
    * @param {[String]} dataType [数据类型(可选)] 如:'json'
    * @param {[String]} pageId [分页id(必须)] 如:"page"
    * @param {[Function]} beforeSend [请求前执行函数(可选)] 如:function(){}
    * @param {[Function]} success [请求成功后执行函数(必须)] 如:function(){}
    * @param {[Number]} pageSize [每页显示条数(可选)] 如:10
    * @param {[Number]} page [从哪条数据开始(可选)] 如:0
    * @param {[Array]} limits [每页条数规格(可选)] 如:[10, 20, 30, 50, 100]
    * @param {[Number]} groups [连续出现的页码个数(可选)] 如:5
    * @param {[Array]} layout [分页排版(可选)] 如:["count", "prev", "page", "next", "limit", "skip"]
    * @param {[String]} theme [自定义主题色(可选)] 如:"#1776f9"
    */
    jQuery.extend({
    layuiPage: function(obj){
    var type = obj.type || 'post',
    url = obj.url,
    data = obj.data || {},
    dataType = obj.dataType||'json',
    pageId = obj.pageId,
    beforeSend = obj.beforeSend || function() {},
    success = obj.success,
    limits = obj.limits || [10, 20, 30, 50, 100],
    groups = obj.groups || 5,
    layout = obj.layout || ['count', 'prev', 'page', 'next', 'limit', 'skip'],
    theme = obj.theme || '#1776f9';

    //每页显示条数
    data.pageSize = obj.pageSize||10;
    //每页从哪条数据开始,相当根据下标对数据截取
    data.page = obj.page||0;

    $.ajax({
    type: type,
    url: url,
    data: data,
    dataType: dataType,
    beforeSend: function(){
    beforeSend();
    },
    success: function(res){
    layui.laypage.render({
    elem: pageId,
    count: res.recordCount, //数据总条数
    limit: data.pageSize,
    limits: limits,
    groups: groups,
    first: '首页',
    last: '尾页',
    layout: layout,
    theme: theme,
    jump: function(o, first) {
    if(first){
    success(res);
    }else{
    data.pageSize = o.limit; //每页显示条数
    data.page = o.limit * (o.curr - 1); //当前页从0开始,需要减1
    $.layuiChangePage(url, data, beforeSend, success, type);
    }
    }
    });
    }
    });
    },
    layuiChangePage: function(url, data, beforeSend, success, type) {
    $.ajax({
    type: type,
    url: url,
    data: data,
    beforeSend: function() {
    beforeSend();
    },
    success: function(res) {
    var res = JSON.parse(res);
    success(res)
    }
    });

    }
    });