我如何使用EJS将路由,基于Node.js和Mongoose的API上的数据发送到客户端。我收到错误list is not defined
...我在这里错过了什么?我认为我在Node中的控制器中做错了。谢谢您的帮助。
EJS
<main>
<ul>
<% list.forEach(response =>{ %>
<li> <%= response.account %> </li>
<% }) %>
</ul>
</main>
节点控制器
// Read All
exports.tracking_list = function (req, res, next) {
Tracking.find({}, function (err, list) {
if (err) return next(err);
res.send(list);
res.render("pages/index", list)
})
}
节点路由器
// Read All
router.get("/list", tracking_controller.tracking_list);
猫鼬模型
let TrackingSchema = new Schema({
account: {type: String, required: true, max: 100},
accountURL: {type: String, required: true, max: 100},
followed: {type: Number, required: true},
followedBack: {type: Number, required: true},
date: Date
});