Skip to content

Instantly share code, notes, and snippets.

@tstachl
Created October 22, 2013 00:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tstachl/7093263 to your computer and use it in GitHub Desktop.
Save tstachl/7093263 to your computer and use it in GitHub Desktop.
This is an example of how you can use the desk.js pagination from the last page to the first page.
// get the first cases page
client.cases(function(err, cases) {
// define a worker function that handles the
// cases and starts over with the previous page
// make sure you have a "callback" (doSomethingElse)
// function defined before going into this loop
function workCases(err, cases) {
// test if cases is null (previous will return null
// if there is no previous page)
if (cases !== null) {
// run your logic on the cases
_.each(cases, function(case) {});
// get the previous page
return cases.previous(workCases);
}
// don't forget to finish the process with
// doing something else.
return doSomethingElse();
}
// start the process with the last page
cases.last(workCases);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment