只需要添加一个文件即可  api/blueprints/find.js     代码如下

/**
* Module dependencies
*/
var util = require('util'),
actionUtil = require('../../node_modules/sails/lib/hooks/blueprints/actionUtil'); /**
* Find Records
*
* get /:modelIdentity
* * /:modelIdentity/find
*
* An API call to find and return model instances from the data adapter
* using the specified criteria. If an id was specified, just the instance
* with that unique id will be returned.
*
* Optional:
* @param {Object} where - the find criteria (passed directly to the ORM)
* @param {Integer} limit - the maximum number of records to send back (useful for pagination)
* @param {Integer} skip - the number of records to skip (useful for pagination)
* @param {String} sort - the order of returned records, e.g. `name ASC` or `age DESC`
* @param {String} callback - default jsonp callback param (i.e. the name of the js function returned)
*/ module.exports = function findRecords (req, res) { // Look up the model
var Model = actionUtil.parseModel(req); // If an `id` param was specified, use the findOne blueprint action
// to grab the particular instance with its primary key === the value
// of the `id` param. (mainly here for compatibility for 0.9, where
// there was no separate `findOne` action)
if ( actionUtil.parsePk(req) ) {
return require('./findOne')(req,res);
} // Lookup for records that match the specified criteria
var query = Model.find()
.where( actionUtil.parseCriteria(req) )
.limit( actionUtil.parseLimit(req) )
.skip( actionUtil.parseSkip(req) )
.sort( actionUtil.parseSort(req) ); // TODO: .populateEach(req.options);
query = actionUtil.populateRequest(query, req);
query.exec(function found(err, matchingRecords) {
if (err) return res.serverError(err); // Only `.watch()` for new instances of the model if
// `autoWatch` is enabled.
if (req._sails.hooks.pubsub && req.isSocket) {
Model.subscribe(req, matchingRecords);
if (req.options.autoWatch) { Model.watch(req); }
// Also subscribe to instances of all associated models
_.each(matchingRecords, function (record) {
actionUtil.subscribeDeep(req, record);
});
} // get pagination info and wrap results in struct var metaInfo,
criteria = actionUtil.parseCriteria(req),
skip = actionUtil.parseSkip(req),
limit = actionUtil.parseLimit(req); Model.count(criteria)
.exec(function(err, total){
if (err) return res.serverError(err); metaInfo = {
start : skip,
end : skip + limit,
limit : limit,
total : total,
criteria: criteria
}; res.ok({info: metaInfo, items: matchingRecords}); });
});
};

  

重写路由(/:modelIdentity/find)

查看效果,请输入如下链接, 详情 请看我的github  https://github.com/shenggen1987/sails-demo.git

http://localhost:1337/order/find?limit=1&skip=1

{
"info": {
"start": 1,
"end": 2,
"limit": 1,
"total": 2,
"criteria": {}
},
"items": [
{
"name": "000",
"age": 92,
"phone": "15268155415",
"createdAt": "2017-02-14T09:15:08.242Z",
"updatedAt": "2017-02-14T09:15:08.242Z",
"id": "58a2ca9c8a7b1e1500883405"
}
]
}

  

node.js---sails项目开发(6)--- 实现分页功能的更多相关文章

  1. Node JS后端项目开发与生产环境总结

    原文地址:Node JS后端项目开发与生产环境总结 Node JS常用后端框架有express.koa.sails.国产框架有个egg js,已经在cnode投入生产了,还有个think js,类似t ...

  2. 前端(Node.js)(3)-- Node.js实战项目开发:“技术问答”

    1.Web 与 Node.js 相关技术介绍 1.1.Web应用的基本组件 web应用的三大部分 brower(GUI)<==>webserver(business logic.data ...

  3. Node.js 从零开发 web server博客项目[express重构博客项目]

    web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...

  4. Node.js 从零开发 web server博客项目[数据存储]

    web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...

  5. Node.js 从零开发 web server博客项目[koa2重构博客项目]

    web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...

  6. Node.js 从零开发 web server博客项目[安全]

    web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...

  7. Node.js 从零开发 web server博客项目[日志]

    web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...

  8. Node.js 从零开发 web server博客项目[登录]

    web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...

  9. Node.js 从零开发 web server博客项目[接口]

    web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...

  10. Node.js 从零开发 web server博客项目[项目介绍]

    web server博客项目 Node.js 从零开发 web server博客项目[项目介绍] Node.js 从零开发 web server博客项目[接口] Node.js 从零开发 web se ...

随机推荐

  1. CodeForces 579b

    B. Finding Team Member time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. Hive分析窗体函数之SUM,AVG,MIN和MAX

    行 AVG(pnum) OVER(PARTITION BYpolno ORDER BY createtime ROWS BETWEEN CURRENT ROW AND UNBOUNDED FOLLOW ...

  3. powerDesigner建表时选择不同数据库类型

    l  使用powerDesigner创建表模型的时候可选择数据库类型 如图设置为mysql:

  4. 飞思卡尔烧写工具mfgtools的使用

    MFGTool是飞思卡尔提供的烧写工具,使用起来非常方便.但是,在使用MFGTool有几点是需要注意的,否则就会在烧写过程中遇到一些问题: 1.在使用MFGTool前,文件cfg.ini 和 UICf ...

  5. centos yum安装及手动编译ettercap

    眼下流行的软件包有二种形式 ,一种是以rpm包,deb包为代表的智能安装包.还有一种是以file.tar.gz形式的压缩 一 智能安装 以 mysql为例 yum search mysqld 二 手动 ...

  6. 再来一个expect脚本

    [root@jenkins scripts]# cat expect_test1205.sh #!/usr/bin/expect ################################### ...

  7. tomcat 内存溢出原因分析及解决

    一.错误提示:java.lang.OutOfMemoryError: Java heap space [原因分析] tomcat默认可以使用内存为128MB,在较大型的应用项目中不足以满足运行要求,在 ...

  8. 基于WebBrowser 的爬虫程序

    WebBrowser的属性和事件 WebBrowser 如何跳转页面 web.Navigate(""); WebBrowser 如何循环跳转获取页面内容 bool loading ...

  9. 【BZOJ】3400: [Usaco2009 Mar]Cow Frisbee Team 奶牛沙盘队(dp)

    http://www.lydsy.com/JudgeOnline/problem.php?id=3400 既然是倍数我们转换成mod.. 设状态f[i][j]表示前i头牛modj的方案 那么答案显然是 ...

  10. scheme 中的宏使用

    #lang scheme ( define-syntax my-when     ( syntax-rules ()       [ ( _ pred body ... )         ( if ...