分頁接口的實現,必須要在服務器上進行開發、隨著時代的進步,各種流和時間線中應該是非常普遍的,今天就讓錯新技術頻道小編來為大家分享nodejs分頁類代碼。
分頁類,我放在 plugin/Paginate.js
?
?
/*
* 當前開始的條數
*/
Paginate.prototype.first = function(){
??? var first = (this.page-1)*this.pagesize;
??? if(first>this.total){
??????? return (this.maxpage-1)*this.pagesize;
??? }
??? return first;
}
/*
* 當前頁最大的條數
*/
Paginate.prototype.last = function(){
??? var last = this.first()+this.pagesize;
??? if(last>this.total){
??????? return this.total;
??? }
??? return last;
}
/**
?* 上一頁
?* @returns {number}
?*/
Paginate.prototype.prev = function(){
??? if(this.page <= 1){
??????? return false;
??? }
??? return this.page-1;
}
/**
?* 下一頁
?* @returns {*}
?*/
Paginate.prototype.next = function(){
??? if(this.page >= this.maxpage){
??????? return false;
??? }
??? return (parseInt(this.page)+1);
}
module.exports = Paginate;
?
使用例子
?
以上就是錯新技術頻道小編分享nodejs分頁類代碼,其實只要花費時間認真學習,大家就會掌握很多的知識。
新聞熱點
疑難解答
圖片精選