I have simple pagination function that outputs array.
exports.pagination = function(currentPage, nrOfPages) {
var delta = 1,
range = [],
rangeWithDots = [],
l;
range.push(1);
if (nrOfPages <= 1){
return range;
}
for (let i = currentPage - delta; i <= currentPage + delta; i++) {
if (i < nrOfPages && i > 1) {
range.push(i);
}
}
range.push(nrOfPages);
for (let i of range) {
if (l) {
if (i - l == 2) {
rangeWithDots.push(l + 1);
} else if (i - l !== 1) {
rangeWithDots.push('...');
}
}
rangeWithDots.push(i);
l = i;
}
return rangeWithDots;
}
handlebars:
{{#each pagination}}
<li class="paginator-item">
<a href="{{this}}" class="paginator-itemLink">{{this}}</a>
</li>
{{/each}}
output:
1 ... 7 8 9 ... 19
It works well. But what i want to do is to seperate "number" and "href" so i can use
{{#each pagination}}
<li class="paginator-item">
<a href="{{this.href}}" class="paginator-itemLink">{{this.number}}</a>
</li>
{{/each}}
But dont know how can i do this but unable. Cant find the correct way.
rangeWithDots.push(number:'...',href:''). Tried lot of things but cant find that one correct