Answer the question
In order to leave comments, you need to log in
How to make pagination in SailsJS?
I decided to start learning SailsJS at first, like everyone else, I watched videocasts with lessons, more or less getting used to it, I began to write code myself, there seemed to be no difficulties, but when I decided to write a simple blog, I ran into a problem with pagination, there is a paginate method in the waterline docks ( ) that performs pagination, or just makes a post limit, the docks are raw, there are only a couple of sentences, and a few lines of code about the method itself, without real use.
It seems, of course, after searching for users, break it down into 10 elements. I decided to do something similar and in the simplest version it turned out thisUser.find().paginate({page: 2, limit: 10});
index: function (req, res, next) {
Blog.find(function (err, blog) {
if (err) return next(err);
res.view({
blog: blog
});
}).paginate();
}
Answer the question
In order to leave comments, you need to log in
You fundamentally wrote the sample incorrectly. Need like this:
getImages: function(req, res) {
var page = req.param('page');
LibraryImage
.find()
.paginate({
page: page,
limit: 20
})
.done(function(error, images) {
if (error) {
res.serverError(error);
} else {
res.json(images);
}
});
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question