只需要添加一个文件即可  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"
}
]
}

  

最新文章

  1. Apache POI使用详解
  2. 工具类 dp转px 获取图片实际尺寸 获取屏幕尺寸
  3. 高德amap 根据坐标获取的地址信息
  4. hdu 3863 No Gambling
  5. 在linux下实现用ffmpeg把YUV420帧保存成图片
  6. 自动计算label字体的高度和图片拉伸处理(封装成分类分享)
  7. Struts2使用拦截器完成权限控制示例
  8. Android UI ActionBar功能-ActionBarSherlock 的使用
  9. Maven 项目 @Override must override a superclass method` 问题
  10. Android逆向之so的半自动化逆向
  11. 18 UI美化自定义主题样式代码
  12. Windows 下使用 工具修改文件的 时间
  13. 【转】win2008 中iis7设置404页面但返回状态200的问题解决办法
  14. java实现点选汉字验证码(转)
  15. 关于 spring MVC 配置自动扫描中 use-default-filters 属性
  16. class空格多类名
  17. attempt to open datawindow failed@安装两个PB软件
  18. PAT A1147 Heaps (30 分)——完全二叉树,层序遍历,后序遍历
  19. 小米路由器设置端口转发远程登录WEB管理页及安装MT工具箱
  20. all index range ref eq_ref const system 索引type说明

热门文章

  1. ORACLE / PLSQL 插入或更新数据的几种方式
  2. NetBeans 设置code completion/auto pop-up delay
  3. vim插件管理器的安装和配置-windows
  4. linux学习笔记32---命令ping和telnet
  5. [J2EE]MyBatis HelloWorld
  6. pl/sql 实例精解 07
  7. (转)c/c++内存对齐问题
  8. db2 设置表 not null
  9. Java面试题全集(上)(中)(下) (转)+自己总结
  10. Appcompat实现Action Bar的兼容性处理