fknop/hapi-pagination

how to custom results?

Closed this issue · 2 comments

I want to not only return results but also want to return others,like I want to return

data: {
  results: [],
  otherInfo: {}
}
fknop commented

Of course, from the docs:

The paginate method also offers a way to add custom properties to your response. You just have to pass an object as first parameter and pass a options.key parameter which is the name of the key of the paginated results.

For example:

return h.paginate({ results: [], otherKey: 'value', otherKey2: 'value2' }, 0, { key: 'results' });

The response will also contains otherKey and otherKey2. Nested keys for the paginated results are not allowed.

If you pass an object but forgot to pass a key for your results, the paginate method will throw an error. Same thing if the key does not exist.

@fknop thanks!