Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 将书架模型上的Knex查询限制为仅返回n条记录_Node.js_Bookshelf.js_Knex.js - Fatal编程技术网

Node.js 将书架模型上的Knex查询限制为仅返回n条记录

Node.js 将书架模型上的Knex查询限制为仅返回n条记录,node.js,bookshelf.js,knex.js,Node.js,Bookshelf.js,Knex.js,我有以下代码,其中我使用splice函数只将前10个/JSON对象传递给JADE模板 app.get('/index', function(req, res) { new models.Condos() .query('orderBy', 'age', 'asc') .fetch() .then(function(names) { var name = names.splice(0,10); res.render('in

我有以下代码,其中我使用splice函数只将前10个/JSON对象传递给JADE模板

app.get('/index', function(req, res) {
    new models.Condos()
      .query('orderBy', 'age', 'asc')
      .fetch()
      .then(function(names) {
        var name = names.splice(0,10);
        res.render('index', {
          names: name.toJSON()
        });
      });
  });
};

有没有什么方法可以限制查询本身只返回前10条记录,而不是使用偏移量和限制参数拼接数组?您可以编写一个knex查询来实现这一点,它看起来类似于:

app.get'/index',functionreq,res{ knex.选择'*' .来自“公寓” 有限公司 .然后是函数名{ rendernames; };
}; 您可以编写一个knex查询来实现这一点,它将类似于:

app.get'/index',functionreq,res{ knex.选择'*' .来自“公寓” 有限公司 .然后是函数名{ rendernames; };
}; 我要找的是更符合这些原则的东西

app.get('/index', function(req, res) {
    new models.Condos()
      .query('orderBy', 'age', 'asc')
      .query('limit','10')
      .fetch()
      .then(function(names) {
        var name = names.splice(0,10);
        res.render('index', {
          names: name.toJSON()
        });
      });
  });
};

我要找的是更符合这些原则的东西

app.get('/index', function(req, res) {
    new models.Condos()
      .query('orderBy', 'age', 'asc')
      .query('limit','10')
      .fetch()
      .then(function(names) {
        var name = names.splice(0,10);
        res.render('index', {
          names: name.toJSON()
        });
      });
  });
};

你可以使用书架上的页码

models.Condos.fetchPage( {page:1, pageSize:10} )
注意:对于第一页,如果页面大小为10,您可以省略参数,只需

models.Condos.fetchPage()

你可以使用书架上的页码

models.Condos.fetchPage( {page:1, pageSize:10} )
注意:对于第一页,如果页面大小为10,您可以省略参数,只需

models.Condos.fetchPage()