How can I comment the EJS code (JS node) without getting an error(如何才能在不出错的情况下注释ejs代码(js节点)?)
本文介绍了如何才能在不出错的情况下注释ejs代码(js节点)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在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 oumiDesktopworkspaceseclipseToDoListviewsx.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 oumiDesktopworkspaceseclipseToDoList
ode_modulesejslibejs.js:455:12), <anonymous>:11:25)
at c:Users oumiDesktopworkspaceseclipseToDoList
ode_modulesejslibejs.js:482:14
at View.exports.renderFile [as engine] (c:Users oumiDesktopworkspaceseclipseToDoList
ode_modulesejslibejs.js:348:31)
at View.render (c:Users oumiDesktopworkspaceseclipseToDoList
ode_modulesexpresslibview.js:93:8)
at EventEmitter.app.render (c:Users oumiDesktopworkspaceseclipseToDoList
ode_modulesexpresslibapplication.js:566:10)
at ServerResponse.res.render (c:Users oumiDesktopworkspaceseclipseToDoList
ode_modulesexpresslib
esponse.js:938:7)
at c:Users oumiDesktopworkspaceseclipseToDoList odoList.js:13:6
at Layer.handle [as handle_request] (c:Users oumiDesktopworkspaceseclipseToDoList
ode_modulesexpresslib
outerlayer.js:82:5)
at next (c:Users oumiDesktopworkspaceseclipseToDoList
ode_modulesexpresslib
outer
oute.js:110:13)
at Route.dispatch (c:Users oumiDesktopworkspaceseclipseToDoList
ode_modulesexpresslib
outer
oute.js:91:3)
如何注释此代码?
推荐答案
有两种解决方案:
<%# comment %>
(来自documentation)<%/* comment */%>
(也可以,但是很难看,使用起来不舒服)
除了突出显示IDE中的语法外,我看不出这些示例之间有什么不同(使用BracketsIDE的示例)。
这篇关于如何才能在不出错的情况下注释ejs代码(js节点)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何才能在不出错的情况下注释ejs代码(js节点)?
基础教程推荐
猜你喜欢
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 我什么时候应该在导入时使用方括号 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01
- 动态更新多个选择框 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01