问题
Can I use pagination or limit + skip that has a return "total page" or "total count" in sails js?
回答1:
I guess you mean when you use sails blueprint api methods? Unfortunately in current sails version (v0.11.3) you can't.
You must send another request for counting. That blueprint method also don't exist in current sails version, but you can use "sails-hook-blueprint-count" package which enable count method with filtering on all defined models.
"sails-hook-blueprint-count" package is available through npm repository (https://www.npmjs.com/package/sails-hook-blueprint-count) and you can install it with
npm install sails-hook-blueprint-count
command.
Then, when you lift sails app you can use routes like
GET /:model/count
or
GET /:model/count?where={:criteria}
:criteria is the same like in find where blueprint methods (http://sailsjs.org/documentation/reference/blueprint-api/find-where).
Response will be json with format
{ count : COUNT }
来源:https://stackoverflow.com/questions/32943436/get-total-count-in-sails-js-blueprint-api