【问题标题】:Impose max limit in Loopback在 Loopback 中施加最大限制
【发布时间】: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 过滤器格式?

【问题讨论】:

标签: swagger loopbackjs strongloop


【解决方案1】:

根据文档here,格式应如下所示:

api/MyModel?filter[where][country]=DE

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-30
    • 2022-01-04
    • 1970-01-01
    • 1970-01-01
    • 2013-07-19
    • 2011-07-25
    • 2017-11-06
    • 1970-01-01
    相关资源
    最近更新 更多