We have MongoDB and a collection in it. The mongoose-paginate plugin is used for paging. The answer comes in this format:
{ docs:Array[10], // ΠΌΠ°ΡΡΠΈΠ² Π΄ΠΎΠΊΡΠΌΠ΅Π½ΡΠΎΠ² Ρ Π½ΡΠΆΠ½ΠΎΠΉ ΡΡΡΠ°Π½ΠΈΡΡ limit:10, // ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠΎΠ² Π½Π° ΡΡΡΠ°Π½ΠΈΡΠ΅ page:1, // Π½ΠΎΠΌΠ΅Ρ ΡΡΡΠ°Π½ΠΈΡΡ pages:9, // ΠΊΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΡΡΡΠ°Π½ΠΈΡ total:88 // Π²ΡΠ΅Π³ΠΎ Π·Π°ΠΏΠΈΡΠ΅ΠΉ ΡΠΎΠΎΡΠ²Π΅ΡΡΡΠ²ΡΡΡΠΈΡ
ΠΊΡΠΈΡΠ΅ΡΠΈΡΠΌ Π²ΡΠ±ΠΎΡΠΊΠΈ }
To generate the buttons I wrote this filter:
/*global angular*/ // /src/js/filters/range.filter.js (function () { 'use strict'; angular .module('App') .filter('range', range); /** * Π€ΠΈΠ»ΡΡΡ Angular * * @constructor * @name range * * @return {Function} ΠΠ΅ΡΠ½Π΅Ρ ΡΠΈΠ»ΡΡΡ Π΄Π»Ρ ΠΌΠ°ΡΡΠΈΠ²Π° */ function range() { /** * Π€ΠΈΠ»ΡΡΡ ΡΠΎΠ·Π΄Π°Π΅Ρ ΠΈΠ· Π²Ρ
ΠΎΠ΄Π½ΠΎΠ³ΠΎ ΠΌΠ°ΡΡΠΈΠ²Π° input ΠΌΠ°ΡΡΠΈΠ² ΡΠΈΡΠ΅Π» Π΄Π»ΠΈΠ½ΠΎΠΉ total * * @method * * @param {Array} input ΠΡΡΡΠΎΠΉ ΠΌΠ°ΡΡΠΈΠ² * @param {Number} total ΠΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΡΡΡΠ°Π½ΠΈΡ * @param {Number} current Π’Π΅ΠΊΡΡΠ°Ρ ΡΡΡΠ°Π½ΠΈΡΠ° * @param {Number} max ΠΠΎΠ»ΠΈΡΠ΅ΡΡΠ²ΠΎ ΠΊΠ½ΠΎΠΏΠΎΠΊ Π΄Π»Ρ ΠΏΠΎΠΊΠ°Π·Π° * * @return {Array} ΠΠ°ΡΡΠΈΠ² Ρ ΡΠΈΡΠ»ΠΎΠ²ΡΠΌΠΈ ΡΠ»Π΅ΠΌΠ΅Π½ΡΠ°ΠΌΠΈ Π΄Π»ΠΈΠ½ΠΎΠΉ max * * @example * <li ng-repeat="num in [] | range:88:2:5">{{num}}</li> * // ΡΠΎΠ·Π΄Π°ΡΡ ΠΌΠ°ΡΡΠΈΠ² Π΄Π»Ρ Π²ΡΠ²ΠΎΠ΄Π° ΠΊΠ½ΠΎΠΏΠΎΠΊ ΠΏΠ΅ΡΠ΅ΠΊΠ»ΡΡΠ΅Π½ΠΈΡ ΡΡΡΠ°Π½ΠΈΡΡ */ return function(input, total, current, max) { console.log("total, current, max:", total, current, max); var total = parseInt(total); var current = parseInt(current); var max = parseInt(max); if(current > (total-max)){ current = current-max; } for (var i=current; i<=(current+max); i++) { if(i <= total){ input.push(i); } } return input; }; } //range.$inject = []; })();
I give screenshots of what happened:
Che can not come up with the logic of generation. Will you help?