我在 EJS 文件中有以下代码:
<table>
<% for(var i=0; i < data.length; i++) { %>
<tr>
<td><%= data[i].id %></td>
<td><%= data[i].name %></td>
</tr>
<% } %>
</table>
当我这样评论的时候,
<!-- <table> -->
<!-- <% for(var i=0; i < data.length; i++) { %> -->
<!-- <tr> -->
<!-- <td><%= data[i].id %></td> -->
<!-- <td><%= data[i].name %></td> -->
<!-- </tr> -->
<!-- <% } %> -->
<!-- </table> -->
我在第 2 行仍然有错误。这是错误的堆栈:
ReferenceError: c:\Users\toumi\Desktop\workspaces\eclipse\ToDoList\views\x.ejs:2
1| <!-- <table> -->
>> 2| <!-- <% for(var i=0; i < data.length; i++) { %> -->
3| <!-- <tr> -->
4| <!-- <td><%= data[i].id %></td> -->
5| <!-- <td><%= data[i].name %></td> -->
data is not defined
at eval (eval at <anonymous> (c:\Users\toumi\Desktop\workspaces\eclipse\ToDoList\node_modules\ejs\lib\ejs.js:455:12), <anonymous>:11:25)
at c:\Users\toumi\Desktop\workspaces\eclipse\ToDoList\node_modules\ejs\lib\ejs.js:482:14
at View.exports.renderFile [as engine] (c:\Users\toumi\Desktop\workspaces\eclipse\ToDoList\node_modules\ejs\lib\ejs.js:348:31)
at View.render (c:\Users\toumi\Desktop\workspaces\eclipse\ToDoList\node_modules\express\lib\view.js:93:8)
at EventEmitter.app.render (c:\Users\toumi\Desktop\workspaces\eclipse\ToDoList\node_modules\express\lib\application.js:566:10)
at ServerResponse.res.render (c:\Users\toumi\Desktop\workspaces\eclipse\ToDoList\node_modules\express\lib\response.js:938:7)
at c:\Users\toumi\Desktop\workspaces\eclipse\ToDoList\todoList.js:13:6
at Layer.handle [as handle_request] (c:\Users\toumi\Desktop\workspaces\eclipse\ToDoList\node_modules\express\lib\router\layer.js:82:5)
at next (c:\Users\toumi\Desktop\workspaces\eclipse\ToDoList\node_modules\express\lib\router\route.js:110:13)
at Route.dispatch (c:\Users\toumi\Desktop\workspaces\eclipse\ToDoList\node_modules\express\lib\router\route.js:91:3)
我如何评论这段代码?
有两种解决方案:
-
<%# comment %>
(来自于文档 http://ejs.co/)
-
<%/* comment */%>
(也可以,但是很丑而且用起来不舒服)
除了在 IDE 中突出显示语法之外,我没有看到这些示例之间的区别(带有Brackets https://en.wikipedia.org/wiki/Brackets_(text_editor) IDE).
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)