【发布时间】:2015-08-23 09:03:33
【问题描述】:
有没有办法在 Loopback 中设置最大限制。我想像这样:
MyModel.paginateFind = function(filter, page, cb){
// Set max limit of 1000
if (filter.limit > 1000) filter.limit = 1000;
// Set pagination
filter.skip = filter.limit * (page - 1);
// Call the standard find function with the new filter
MyModel.find(filter, function(err, res){
cb(err, res);
});
}
MyModel.remoteMethod(
'paginatedFind',
{
http: {path: '/', verb: 'get'},
accepts: [
{arg: 'filter', type: 'object'},
{arg: 'page', type: 'number'}
],
returns: {arg: 'result', type: 'object'}
}
);
这在过滤器被格式化为 json 时有效,但不是这种格式:http://localhost:3000/api/MyModel?filter=[where][country]=DE。如何使用标准的 StongLoop 过滤器格式?
【问题讨论】:
-
您是否正在寻找与
skip filter齐头并进的limit filter? docs.strongloop.com/display/public/LB/Limit+filter -
是的,但我不知道如何在模型的自定义函数/端点中操作过滤器。我敢肯定这是非常简单的事情。
-
你的伪代码看起来很准确~对我来说……你已经在gitter.im/strongloop/loopback上问过了吗?
标签: swagger loopbackjs strongloop