J'ai mis la classe Paged dans Plugin / Paginate.js
La copie de code est la suivante:
/ **
* Classe de plugin de pagination (compte d'affichage manquant par page, Listrows sera écrit demain)
* Page @param {numéro} Page actuelle
* @param pagesize {nombre} nombre d'enregistrements par page
* @param total {nombre} enregistrements totaux
* @constructor
* /
fonction Paginate (page, pagesize, total) {
if (! Page || Page <1) {
page = 1;
}
if (! pagesize || pagesize <1) {
pagesize = 20;
}
if (! Total || Total <0) {
total = 0;
}
this.pagesize = pagesize;
this.total = total;
if (this.total% this.pagesize === 0) {
this.maxPage = paSeInt (this.total/this.pageSize);
}autre{
this.maxPage = paSeInt (this.total /this.pageSize) + 1;
}
if (page> this.maxpage) {
this.page = this.maxpage;
}autre{
this.page = page;
}
}
/ *
* Le nombre actuel d'entrées
* /
Paginate.prototype.first = function () {
var d'abord = (this.page-1) * this.pageSize;
if (d'abord> this.total) {
return (this.maxpage-1) * this.pageSize;
}
retour en premier;
}
/ *
* Le plus grand nombre d'entrées sur la page actuelle
* /
Paginate.prototype.last = function () {
var dernier = this.first () + this.pagesize;
if (dernier> this.total) {
Renvoyez ce.total;
}
retour en dernier;
}
/ **
* Page précédente
* @returns {numéro}
* /
Paginate.prototype.prev = function () {
if (this.page <= 1) {
retourne false;
}
Renvoyez ce.page-1;
}
/ **
* Page suivante
* @returns {*}
* /
Paginate.prototype.next = function () {
if (this.page> = this.maxpage) {
retourne false;
}
return (parseInt (this.page) +1);
}
module.exports = paginate;
Utiliser l'exemple
La copie de code est la suivante:
var paginate = require ("../ plugin / paginate");
var q = req.query.q;
var paginate = nouveau paginat (q, 10, 185);
var page = page.page; // Compte de page actuel
var d'abord = paginate.first (); // le premier élément actuel
var dernier = paginate.last (); // le nombre maximum actuel d'entrées
var maxpage = paginate.maxpage; // nombre total de pages
var pagesize = paginate.pagesize; // nombre d'affichage par page
var total = paginate.total; // nombre total d'enregistrements
var prev = paginate.prev (); // précédent
var next = paginate.next (); // suivant
res.json ({page: page, premier: premier, dernier: dernier, maxpage: maxpage, pagesize: pagesize, total: total, prev: prev, ne suivant: suivant})