V
V
Vlad Timofeev2015-01-09 18:29:04
MongoDB
Vlad Timofeev, 2015-01-09 18:29:04

How to distribute data from the server to pages?

Good time.
Let's say data about registered users comes from the server in this way:

app.get('/users', function (req, res) {
  User.find(function(err, users) {
    var allUsers = [];
    		for (var i = users.length - 1; i >= 0; i--) {
    			var person = {
    				name: users[i].name,
    				photoMax: users[i].photoMax,
    				about: users[i].about,
    				score: users[i].score,
    				contacts: users[i].contacts
    			};
    			allUsers.push(person);
    }
    res.render('users', {
      page: 'users',
      user : req.user,
      users: allUsers,
    });
  });
});

And with jade & css
- each anotherUser in users
     .row
            ul
               li тут имя
               li тут др.данные юзера

It turns out something like this:
40f26361ef3340f19d2761191090b6e8.png
========================================== =============================================
=== ================================================= ====================================
Over time, there will be quite a few users -> we need to make pages, but I can’t figure out how to organize them .. Please tell me ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Matvey Kukuy, 2015-01-09
@Matvey-Kuk

You may not know, but it's called "pagination", the first link on google leads to https://github.com/expressjs/express-paginate .

A
Alexander Aksentiev, 2015-01-09
@Sanasol

As an everywhere.
When processing the request, take into account the necessary page from the get parameter.
In the selection, set limit and offset

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question