我正在使用一个新项目,并且我正在使用node.js和mongodb。在项目中,我尝试从数据库中获取数据并将其显示在manacc.ejs文件的表中。但它显示以下错误:
SyntaxError: Unexpected identifier in E:\etsp\nodetest1\views\manacc.ejs while compiling ejs
at Function (native)
at Object.Template.compile (E:\etsp\nodetest1\node_modules\ejs\lib\ejs.js:455:12)
at Object.compile (E:\etsp\nodetest1\node_modules\ejs\lib\ejs.js:288:16)
at handleCache (E:\etsp\nodetest1\node_modules\ejs\lib\ejs.js:147:16)
at View.exports.renderFile [as engine] (E:\etsp\nodetest1\node_modules\ejs\lib\ejs.js:348:14)
at View.render (E:\etsp\nodetest1\node_modules\express.io\node_modules\express\lib\view.js:76:8)
at Function.app.render (E:\etsp\nodetest1\node_modules\express.io\node_modules\express\lib\application.js:504:10)
at ServerResponse.res.render (E:\etsp\nodetest1\node_modules\express.io\node_modules\express\lib\response.js:798:7)
at Promise.<anonymous> (E:\etsp\nodetest1\routes\index.js:297:9)
at Promise.<anonymous> (E:\etsp\nodetest1\node_modules\monk\node_modules\mpromise\lib\promise.js:178:8)
以下是index.js
视图
manacc.ejs
文件获取方法
router.get('/viewusers', function(req, res) {
var usersess=req.session.username;
var db = req.db;
var collection = db.get('users');
collection.find({},{},function(e,docs){
res.render('manacc', { title: 'custermize',user:usersess,viewusers:docs});
});
});
<%foreach(viewusers as var user) { %>
<tr >
<td> <%=user.username %> </td>
<td> <%=user.name %> </td>
<td> <%=user.email %> </td>
<a href="/editusers/<?php //echo $row['_id']; ?>">
</a>
<a style="cursor:pointer;" >
</a>
</tr>
<% } %>
<%endforeach%>
</table>