0.0.3 • Published 6 years ago

ly_paging v0.0.3

Weekly downloads
3
License
ISC
Repository
-
Last release
6 years ago

分页模块

调用url查询数据,根据template模版生成html,渲染到container中

1.安装

npm i --save ly_auto

2.使用

var Paging = require('@yj/paging');
new Paging({
    template: require('./tab.handlebars'),
    url: '/test.json',
    container: '#div1'
});

3.配置项

template: 模版,应为handlebars渲染函数
tpl: 同template
url: 数据查询接口
container:模版渲染目标,注意该目标中原有内容会被清除
autoLoad: 组件初始化后自动查询一次,默认为true
hashSave: 在hash中记录页码,使刷新后仍然保持页码,并支持浏览器后退,默认为true
param:调用查询接口时默认传递pageNo参数,如需传递更多参数,需配置该项,可配置为{}或者function
beforeQuery:function(),查询前的回调函数
afterQuery:function(res) 查询完成的回调函数,res为服务端返回的值
afterRender:function(data)模版渲染完成后的回调函数,data为渲染时使用的数据
beforeRender:function(data)模版渲染前调用,可以在其中对数据进行预处理,回调return false会终止渲染

4.方法

setParam(param): 变更param,参数可以是{}或function
toPage(pageNo, callback):跳到指定页,callback在跳转完成后调用
prev(): 跳到上一页
next(): 跳到下一页
render(data):按照数据渲染模版

5.功能class约定

模版中支持以下功能性class
js-first: 该元素触发跳到首页功能
js-end: 该元素触发跳到末页功能
js-next: 该元素触发下一页功能
js-prev: 该元素触发上一页功能
js-topage: 该元素触发跳到某页功能,页码取data-pagenum-target(该属性应符合jquery选择器规范)属性指向的元素value,如无该属性,取元素文本