Help with paging with Express-Handlebars and Mongoose

Asked

Viewed 26 times

0

I’m using the Express-Handlebars and the Mongoose, I want to make a page, I think I got the code on the model, but I got lost in time to pass it to the handlebars and then, I decided to come here.

Codes:

Model.:

    const query = {};
    const page = req.query.page
    const limit = 10
    const skip = limit * (page - 1)
    Usuario.find(query).skip(skip).limit(limit).lean().then((data) => {
        res.render("admin/users", {data: data})
    })

Handlebars:

    <div class="container mt-4">
    {{#each data}}
            <div class="margindiv">
                <p class="lead">
                Username: <strong>{{username}}</strong> <br>
                Email: <strong>{{email}}</strong> <br>
                Cargo: <strong>{{cargo}}</strong> <br>
                Ativo: <strong>{{ativo}}</strong> <br>
                Administrador: <strong>{{acesso}}</strong>
                </p>
            <a href="/admin/userdelet/{{_id}}"><button class="btn btn-danger mt-2">Deletar</button></a>
            <a href="/admin/userdelet/{{_id}}"><button class="btn btn-warning mt-2">Editar usuário</button></a>
            </div>
     {{else}}
      Nenhum usuário encontrado.
     {{/each}}
     </div>
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.