add Paging functions
Closed this issue · 1 comments
kellyjandrews commented
When a payload is returned, it currently includes next
or prev
if there are additional results.
The user currently must call those routes directly - but this should provide .next()
or .prev()
functions to return the next/previous results with less effort.
devintyler commented
var account = new Syncano({accountKey: "ACCOUNT-KEY"});
var currentPage; // store current page to be used in next/prev calls
account.instance('INSTANCE').class('CLASS').dataobject().list()
.then(function(res){
console.log(res);
currentPage = res;
})
.catch(function(err) {
console.log(err)
});
function prev() {
if (currentPage.prev != null) {
currentPage.prev()
.then(function(res){
console.log(res);
currentPage = res;
})
.catch(function(err) {
console.log(err)
});
} else {
console.log("There are no more objects");
}
}
function next() {
if (currentPage.next != null) {
currentPage.next()
.then(function(res){
console.log(res);
currentPage = res;
})
.catch(function(err) {
console.log(err)
});
} else {
console.log("There are no more objects!");
}
}