我正在尝试在Node.js应用程序中显示mongodb数据库中的项目列表。我使用ejs作为模板引擎。我在页面上遇到以下错误:
路由器代码:
const express = require('express');
const router = express.Router();
// Get page model
var Page = require('../models/page');
// GET page index
router.get('/', function(req, res) {
Page.findOne({}).sort({sorting: 1}).exec(function(err, pages) {
res.render('admin/pages', {
pages: pages
});
});
});
EJS代码:
<%- include('../_layouts/adminheader') %>
<h2 class="page-title">Pages</h2>
<a href="/admin/pages/add-page" class="btn btn-primary">Add a new page</a>
<br><br>
<table class="table table-striped">
<thead>
<tr>
<th>Title</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
<tbody>
<% pages.forEach(function(page) { %>
<tr>
<td><%= page.title %></td>
<td><a href="/admin/pages/edit-page/<%= page.slug %>">Edit</a></td>
<td><a href="/admin/pages/edit-page/<%= page._id %>">Delete</a></td>
</tr>
<% }); %>
</tbody>
</table>
<%- include('../_layouts/adminfooter') %>