婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁 > 知識庫 > 前后端結合實現amazeUI分頁效果

前后端結合實現amazeUI分頁效果

熱門標簽:南昌仁和怎么申請開通400電話 電話機器人黑斑馬免費 拓展地圖標注 電話機器人電銷系統掙話費 平涼地圖標注位置怎么弄 高德地圖標注地點糾錯 機器人外呼系統存在哪些能力 如何獲取地圖標注客戶 只辦理400電話

前后端結合實現amazeUI分頁,代碼如下所示;

借鑒

本文在博客https://blog.csdn.net/brave_coder/article/details/52367124的基礎上實現的,非常感謝大佬的分享。

前端實現

1、引入paginator.js

(function ($) {
    $.fn.paginator = function (options) {
        //this指向當前的選擇器
        var config = {
            url: "",
            pageParent: "",
            totalBars: -1,
            limit: -1,
            offset: 1,
            callback: null
        }
        //合并參數
        var opts = $.extend(config, options);
 
        opts.totalBars = Math.ceil(opts.totalBars / opts.limit);
        //計算按鈕的總個數
 
        //獲取offset參數
        var queryString = function (url) {
            var offset = (url.split("?")[1]).split("=")[1];
            return parseInt(offset);
        }
 
        //ajax核心方法,用于分頁的數據操作
        var ajaxCore = function (offset, fn) {
            $.ajax({
                "url": opts.url,
                "data": {
                    "offset": offset,
                    "limit": opts.limit
                },
                "dataType": "JSON",
                "method": "POST",
                "success": fn
            });
        }
 
        //重新裝配分頁按鈕
        var pageCore = function (offset) {
            if (opts.offset == offset) {
                return;
            } //如果是當前頁面,那么就什么事都不用干了!
            else {
                ajaxCore(offset, opts.callback);
                $(opts.pageParent).empty();
                //否則,清空所有的節點,重新向DOM插入新的分頁按鈕
                var output = "";
                var nextBar = offset == opts.totalBars ? "<li class=\&;am-disabled\&;><a yxhref=\&;javascript:;\&;>»</a></li>" : "<li><a yxhref=\&;" + opts.url + (offset + 1) + "\&;>»</a></li>";
                var preBar = offset == 1 ? "<li class=\&;am-disabled\&;><a yxhref=\&;javascript:;\&;>«</a></li>" : "<li><a yxhref=\&;" + opts.url + (offset - 1) + "\&;>«</a></li>";
                //組裝向上一個節點和下一頁節點
                if (opts.totalBars > 7) {
                    if (offset < 5) {
                        output += preBar;
                        for (var i = 1; i <= 5; i++) {
                            if (i == offset) {
                                output += "<li class=\&;am-active\&;><a yxhref=\&;" + opts.url + offset + "\&;>" + offset + "</a></li>";
                            } else {
                                output += "<li><a yxhref=\&;" + opts.url + i + "\&;>" + i + "</a></li>";
                            }
                        }
                        output += "<li><span>...</span></li>";
                        output += "<li><a yxhref=\&;" + opts.url + (opts.totalBars) + "\&;>" + (opts.totalBars) + "</a></li>" + nextBar;
                    } else if (offset >= 5 && offset <= opts.totalBars - 4) {
                        //當頁面大于7個的時候,那么在第五個和倒數第五個時,執行
                        output += preBar;
                        output += "<li><a yxhref=\&;" + opts.url + 1 + "\&;>" + 1 + "</a></li>";
                        //第一個
                        output += "<li><span>...</span></li>"; //省略號
 
                        output += "<li><a yxhref=\&;" + opts.url + (offset - 1) + "\&;>" + (offset - 1) + "</a></li>";
 
                        output += "<li class=\&;am-active\&;><a  yxhref=\&;" + opts.url + offset + "\&;>" + offset + "</a></li>";
 
                        output += "<li><a yxhref=\&;" + opts.url + (offset + 1) + "\&;>" + (offset + 1) + "</a></li>";
 
                        output += "<li><span>...</span></li>"; //省略號;
 
                        output += "<li><a yxhref=\&;" + opts.url + (opts.totalBars) + "\&;>" + (opts.totalBars) + "</a></li>"; //尾頁
 
                        output += nextBar;
 
                    } else if (offset > opts.totalBars - 4 && offset <= opts.totalBars) {
                        //當頁面位于倒數第四個時候
                        output += preBar;
                        output += "<li><a yxhref=\&;" + opts.url + 1 + "\&;>" + 1 + "</a></li>" + "<li><span>...</span></li>";
 
                        for (var j = 4; j >= 0; j--) {
                            if (opts.totalBars - j == offset) {
                                output += "<li class=\&;am-active\&;><a yxhref=\&;" + opts.url + (opts.totalBars - j) + "\&;>" + (opts.totalBars - j) + "</a></li>";
                            } else {
                                output += "<li><a yxhref=\&;" + opts.url + (opts.totalBars - j) + "\&;>" + (opts.totalBars - j) + "</a></li>";
                            }
                        }
                        output += nextBar;
                    } else {
                        console.log("分頁數據出錯!");
                        return;
                    }
                } else {
                    output += preBar;
                    for (var i = 1; i <= opts.totalBars; i++) {
                        if (i == offset) {
                            output += "<li class=\&;am-active\&;><a yxhref=\&;" + opts.url + offset + "\&;>" + offset+ "</a></li>";
                        } else {
                            output += "<li><a yxhref=\&;" + opts.url + i + "\&;>" + i+ "</a></li>";
                        }
                    }
                    output += nextBar;
                }
                $(opts.pageParent).append(output);
                opts.offset = offset; //將偏移量賦值給config里面的offset
            }
        }
 
        //清理函數,防止多綁定事件和重新計算分頁
        var clear = function () {
            $(opts.pageParent).empty().undelegate();
        }
 
 
        //初始化裝配分頁按鈕
        var init = function (fn) {
            if (typeof (fn) != "function") {
                console.log("將不能正確的執行回調函數");
            } else {
                opts.callback = fn;
            }
            clear();
            ajaxCore(1, opts.callback);//執行初始化ajax方法
            var preBar = "<li class=\&;am-disabled\&;><a yxhref=\&;javascript:;\&;>«</a></li>";
            //上一頁,(禁用的效果)
            //如果只有一頁,那么禁用下一頁
            var nextBar = opts.totalBars > 1 ? "<li><a yxhref=\&;" + opts.url + 2 + "\&;>»</a></li>" : "<li class=\&;am-disabled\&;><a yxhref=\&;javascript:;\&;>»</a></li>";
            //最后一頁
            var output = "<li class=\&;am-active\&;><a yxhref=\&;" + opts.url + 1 + "\&;>1</a></li>";
 
            if (opts.totalBars <= 7) {
                for (var i = 1; i < opts.totalBars; i++) {
                    output += "<li><a yxhref=\&;" + opts.url + (i + 1) + "\&;>" + (i + 1) + "</a></li>";
                }
            } else {
                for (var j = 1; j < 5; j++) {
                    output += "<li><a yxhref=\&;" + opts.url + (j + 1) + "\&;>" + (j + 1) + "</a></li>";
                }
                output += "<li><span>...</span></li>";
                output += "<li><a yxhref=\&;" + opts.url + (opts.totalBars) + "\&;>" + (opts.totalBars) + "</a></li>";
            }
            $(opts.pageParent).delegate("a","click", function () {
                var offset = queryString($(this).attr("yxhref"));
                console.log("ok");
                pageCore(offset);
            });
            $(opts.pageParent).append(preBar + output + nextBar);
        };
        init(opts.callback);//初始化分頁引擎
    }
}(window.jQuery))

2、獲取總頁數,再獲取分頁

$.ajax({
        type: "GET",
        url: selectSendNumberNumsByContURL,//獲取總數
        data: {},
        dataType: "json",
        success: function(data){

            if (data[0].code == 200) {

                $("#paginator").paginator({
                    url: selectSendNumberByContURL + "?offsets=",
                    pageParent: "#paginator",
                    totalBars: data[0].allNums,
                    limit: 10,
                    offset: 1,
                    callback: function (data1) {

                        //清空DOM節點
                        
                        //動態加dom節點
                    }
                });
            }else{

            }
        },
        error: function (err) {

        }
    });

后端實現(分頁)

這里是controller,拿到offset(第幾頁)參數、limit(每頁多少數量),再寫SQL實現分頁就好了。

@RequestMapping(value = "/selectNumberCheckByCont", method = RequestMethod.POST)
    @ResponseBody
    public List<ReturnUtils> selectNumberCheckByCont(HttpServletRequest request,
                                                     HttpServletResponse response) throws Exception {

        //統一設置返回數據格式
        response.setContentType("application/json");
        response.setHeader("Pragma", "no-cache");
        response.setCharacterEncoding("UTF-8");

        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");

        List<ReturnUtils> list = iNumberCheckService.selectNumberCheckByCont(offset, limit);

        return list;
    }

總結

到此這篇關于前后端結合實現amazeUI分頁的文章就介紹到這了,更多相關amazeUI分頁內容請搜索腳本之家以前的文章或繼續瀏覽下面的相關文章,希望大家以后多多支持腳本之家!

標簽:西藏 青島 新疆 棗莊 遼源 池州 永州 漯河

巨人網絡通訊聲明:本文標題《前后端結合實現amazeUI分頁效果》,本文關鍵詞  前,后端,結合,實現,amazeUI,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《前后端結合實現amazeUI分頁效果》相關的同類信息!
  • 本頁收集關于前后端結合實現amazeUI分頁效果的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 湟源县| 抚宁县| 江山市| 新干县| 年辖:市辖区| 汝州市| 拜泉县| 长子县| 青铜峡市| 怀仁县| 桦甸市| 南宫市| 上思县| 泸州市| 靖江市| 锦屏县| 卢氏县| 本溪| 得荣县| 阿拉善左旗| 固安县| 颍上县| 易门县| 刚察县| 双牌县| 体育| 仁怀市| 峨眉山市| 玛沁县| 原阳县| 斗六市| 广丰县| 津市市| 龙海市| 乌恰县| 亚东县| 抚州市| 东阿县| 金昌市| 大新县| 荃湾区|