公用分页模块之knockout

本文介绍如何在时间紧迫的情况下,利用Require和Knockout快速构建一个前端分页组件。虽然分页底部栏是从网上借鉴而来,但整体思路和实现方式展示了自定义公用分页模块的思想。
摘要由CSDN通过智能技术生成

因为工程中使用了require,knockout,所以就自己琢磨着写一个公用的分页模块来用,格式上可能不太正规,我传递个思想大笑

1.分页底部栏没有自己去写,毕竟赶时间,就借鉴了一个网上的(对于作者表示很抱歉,找不到你了尴尬

   在require的path里我配置为 paging

/*
 * Contact: 55342775@qq.com
 */
(function(root, factory) {
	// amd
	if (typeof define === 'function' && define.amd) {
		define([ 'query' ], factory);
	} else if (typeof exports === 'object') { // umd
		module.exports = factory();
	} else {
		root.Paging = factory(window.Zepto || window.jQuery || Query);
	}
})
		(
				this,
				function(Query) {
					$.fn.Paging = function(settings) {
						var arr = [];
						$(this).each(function() {
							var options = $.extend({
								target : $(this)
							}, settings);
							var lz = new Paging();
							lz.init(options);
							arr.push(lz);
						});
						return arr;
					};

					function Paging() {
						var rnd = Math.random().toString().replace('.', '');
						this.id = 'Paging_' + rnd;
					}
					Paging.prototype = {
						init : function(settings) {
							this.settings = $.extend({
								callback : null,
								pagesize : 10,
								current : 1,
								prevTpl : "上一页",
								nextTpl : "下一页",
								firstTpl : "首页",
								lastTpl : "末页",
								ellipseTpl : "...",
								toolbar : false,
								hash : true,
								pageSizeList : [ 5, 10, 15, 20 ]
							}, settings);
							this.target = $(this.settings.target);
							this.container = $('<div id="' + this.id
									+ '" class="ui-paging-container"/>');
							this.target.append(this.container);
							this.render(this.settings);
							this.format();
							this.bindEvent();
						},
						render : function(ops) {
							this.count = ops.count || this.settings.count;
							this.pagesize = ops.pagesize
									|| this.settings.pagesize;
							this.current = ops.current || this.settings.current;
							this.pagecount = Math.ceil(this.count
									/ this.pagesize);
							this.format();
						},
						bindEvent : function() {
							var _this = this;
							this.container
									.on(
											'click',
											'li.js-page-action,li.ui-pager',
											function(e) {
												if ($(this).hasClass(
														'ui-pager-disabled')
														|| $(th
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值