I have a books
collection in MongoDB with fields:
title: title,
description: description,
author: author,
bookSource: bookSource,
imageSource: imageSource
I want to show all of them on the page. I use ejs
engine with node.js
and Express
. I'll find all db records via
var all_books = Book.find();
// and render
res.render("booksPage", { all_books: all_books });
and then I make for
-cycle in ejs
-page:
<div class="booksBox">
<% for (var i = 0; i < all_books.length; i++) { %>
<div class="book">
<p class="title"> <%= all_books[i]["title"] %> </p>
<p class="description"> <%= all_books[i]["description"] %> </p>
<p class="author"> <%= all_books[i]["author"] %> </p>
<!-- And so on.. -->
</div>
<% } //end for cycle %>
</div>
Is it correctly ? How to do this properly?
How I can show result separated by pages?
via user7103883
No comments:
Post a Comment