【发布时间】:2015-12-14 05:05:18
【问题描述】:
我正在尝试获取我的 MySQL 表的数据并使用 EJS 在 HTML 中打印它们,但这不起作用。它告诉我print not defined。我该怎么办?
router.get('/data', function(req, res){
res.render('print', {req : req, res : res});
connection.query('SELECT * FROM users', function(err, result) {
if(err){
throw err;
} else {
for(x in result){
res.locals.print = result[x];
console.log(result[x]);
}
}
});
});
<!doctype html>
<html>
<body>
<div>
<%= print %>
</div>
</body>
</html>
【问题讨论】: