如何通过前后端结合实现amazeUI分页效果
发表于:2024-10-23 作者:千家信息网编辑
千家信息网最后更新 2024年10月23日,这篇文章主要介绍了如何通过前后端结合实现amazeUI分页效果的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇如何通过前后端结合实现amazeUI分页效果文章都会有所收获,
千家信息网最后更新 2024年10月23日如何通过前后端结合实现amazeUI分页效果» " : "» "; var preBar = offset == 1 ? "« " : "« "; //组装向上一个节点和下一页节点 if (opts.totalBars > 7) { if (offset < 5) { output += preBar; for (var i = 1; i <= 5; i++) { if (i == offset) { output += "" + offset + " "; } else { output += "" + i + " "; } } output += "... "; output += "" + (opts.totalBars) + " " + nextBar; } else if (offset >= 5 && offset <= opts.totalBars - 4) { //当页面大于7个的时候,那么在第五个和倒数第五个时,执行 output += preBar; output += "" + 1 + " "; //第一个 output += "... "; //省略号 output += "" + (offset - 1) + " "; output += "" + offset + " "; output += "" + (offset + 1) + " "; output += "... "; //省略号; output += "" + (opts.totalBars) + " "; //尾页 output += nextBar; } else if (offset > opts.totalBars - 4 && offset <= opts.totalBars) { //当页面位于倒数第四个时候 output += preBar; output += "" + 1 + " " + "... "; for (var j = 4; j >= 0; j--) { if (opts.totalBars - j == offset) { output += "" + (opts.totalBars - j) + " "; } else { output += "" + (opts.totalBars - j) + " "; } } output += nextBar; } else { console.log("分页数据出错!"); return; } } else { output += preBar; for (var i = 1; i <= opts.totalBars; i++) { if (i == offset) { output += "" + offset+ " "; } else { output += "" + i+ " "; } } 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 = "« "; //上一页,(禁用的效果) //如果只有一页,那么禁用下一页 var nextBar = opts.totalBars > 1 ? "» " : "» "; //最后一页 var output = "1 "; if (opts.totalBars <= 7) { for (var i = 1; i < opts.totalBars; i++) { output += "" + (i + 1) + " "; } } else { for (var j = 1; j < 5; j++) { output += "" + (j + 1) + " "; } output += "... "; output += "" + (opts.totalBars) + " "; } $(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))
这篇文章主要介绍了如何通过前后端结合实现amazeUI分页效果的相关知识,内容详细易懂,操作简单快捷,具有一定借鉴价值,相信大家阅读完这篇如何通过前后端结合实现amazeUI分页效果文章都会有所收获,下面我们一起来看看吧。
前端实现
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 ? "
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 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 list = iNumberCheckService.selectNumberCheckByCont(offset, limit); return list; }
关于"如何通过前后端结合实现amazeUI分页效果"这篇文章的内容就介绍到这里,感谢各位的阅读!相信大家对"如何通过前后端结合实现amazeUI分页效果"知识都有一定的了解,大家如果还想学习更多知识,欢迎关注行业资讯频道。
效果
节点
按钮
参数
数据
知识
页面
内容
函数
方法
时候
省略号
篇文章
装配
不用
个数
事件
价值
前端
动态
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
论述网络安全的机遇及挑战
sql数据删除数据库
珠海酒店软件开发咨询
cdn测试服务器
魔兽世界怀旧服神仙服务器
网络安全10
张家港中高端服务器应用范围
psm和seer数据库
数据库技术与应用 关系是
我的世界服务器国际版怎么加账号
卫星的软件开发
数据库 属性概念
中卫亚马逊服务器
计算机网络技术岗位发展
高科技与互联网大屏
信息网络安全监察就业
笔记本的网络安全模式怎么进
网络安全工作得到落实
炒号族车牌数据库
牛大网络技术服务
软件开发常见比赛
网络安全专业出国留学
筛选重复数据库
来宾软件开发公司
教育软件开发合肥
国内云服务器能干啥
中绿新世纪网络技术
云计算软件开发工程师怎么样
去除直流分量软件开发
opp公司服务端软件开发