fknop / hapi-pagination

Hapi plugin to handle "custom" pagination
MIT License
63 stars 36 forks source link

how to custom results? #72

Closed zp1112 closed 5 years ago

zp1112 commented 5 years ago

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

data: {
  results: [],
  otherInfo: {}
}
fknop commented 5 years ago

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.
zp1112 commented 5 years ago

@fknop thanks!