最近做的一个项目,整个页面的数据更新要纯ajax实现,没办法,连分页都得由我来写了,基本思路还是像后台那样实现分页,后台实现分页其实也就是用后台的程序来处理那段分页的模版,于是我想
下面是分页的模版:
1.[代码][JavaScript]代码
http://www.cnblogs.com/hust/archive/2011/06/25/2090465.html
{{if(data.totalpage>1){ }}
{{ if(data.curpage!=1){}}
上一页
{{ } }}
{{for(var a=parseInt((data.curpage-1)/Ybole.page.perpage)*Ybole.page.perpage,i=a+1;i<=Math.min(a+Ybole.page.perpage,data.totalpage);i++){}}
{{=i}}
{{ } }}
{{ if(Math.ceil(data.totalpage/Ybole.page.perpage)!= Math.ceil(data.curpage/Ybole.page.perpage)){ }}
...
{{ } }}
{{ if(data.curpage!=data.totalpage){ }}
下一页
{{ } }}
{{ } }}
一下是模版处理代码
var pageTpl=Template({
tpl:$('#pagetpl')[0].text,
data:{curpage:1,totalpage:1}
});
Ybole.page={
curpage:1,
totalpage:1,
perpage:10,//每页显示的条数
previous:function(){
this.curpage=this.curpage-1;
this.goto(this.curpage);
},
next:function(){
this.curpage=this.curpage+1;
this.goto(this.curpage);
},
goto:function(n){
this.curpage=n;
dosomething();
$('#page').html(pageTpl.render({curpage:n}));
}
}