我使用Knex.js & Objection.js,我想显示国家下拉列表,所以我需要所有的行,但它只返回给我10行。如何覆盖分页功能?
我可以在url localhost:3031/countires中设置参数吗?pages=‘All’,应该有一些简单的方法。我使用的是"knex":"^0.21.1",“反对”:"^1.6.11“版本。default.js容器
"paginate": {
"default": 10,
"max": 2000
},目前,我只在src\serivices\countries\countires.services.js中做了以下更改
module.exports = function (app) {
const options = {
Model: createModel(app),
//paginate: app.get("paginate"),
paginate: {
default: 0,
max: 0,
},
};
// Initialize our service with any options it requires
app.use("/countries", new Countries(options, app));发布于 2021-07-08 11:00:22
我发现解决方案需要在获取钩子之前添加应用程序或服务。在我的例子中,我将其添加到/src/app.hooks.js
module.exports = {
before: {
find: [
(hook) => {
if (hook.params.query && hook.params.query.$paginate) {
hook.params.paginate =
hook.params.query.$paginate === "false" ||
hook.params.query.$paginate === false;
delete hook.params.query.$paginate;
}
return hook;
},
],
}
}如何从邮递员调用它:
GET http://localhost:3031/institutes?$paginate=false // all rows
GET http://localhost:3031/institutes //Using paginationNuxt.js
async mounted() {
this.countries = await this.$api.countries.find({ $paginate: false });
},vue.js
this.countries = await this.$axios.get('http://localhost:3031/countries?$paginate=false');发布于 2021-07-02 00:57:21
如果我能看到你对这条路线的异议查询,那将是有帮助的。但您最有可能在paginate中设置一个值,如下所示:
paginate = {
isPage: false,
default:10,
max:2000
}
然后,在查询中可以使用if语句来检查isPage值是true还是false。并且仅当您将该值设置为true时才限制响应。如下所示:
const countries = paginate.isPage
? await Country.query()
.limit(paginate.default)
: await Country.query()
如果你需要更多的帮助,请回复我,我会尽我所能给你回复!
https://stackoverflow.com/questions/68177937
复制相似问题