/* * 分页模型 */ import { HttpModule, Http, Response, RequestOptions, Headers } from '@angular/http'; export class PageModel{ constructor( public http:Http, //Http对象 public url:string, //数据请求地址 public limit:number //每次数据限制量 ){ this.http=http; this.url=url; this.limit=limit; } datas=[]; total=0; offset=0; page=0; pagenow=0; getData(callback:Function){ this.http.post(this.url,{offset:this.offset,limit:this.limit}).subscribe((res:Response)=>{ let json=res.json(); this.total=json.total; this.offset+=json.rows.length; this.datas=json.rows; this.page= Math.ceil(this.total/this.limit); this.pagenow=Math.ceil(this.offset/this.limit); callback({page:this.page,pagenow:this.pagenow,datas:this.datas}); },(error:Response)=>{alert("请求失败");}); } public getNext(callback:Function){ if(this.pagenow>=this.page)return; this.getData(callback); } }