如何才能在不出错的情况下注释ejs代码(js节点)? [英] How can I comment the EJS code (JS node) without getting an error

查看:36
本文介绍了如何才能在不出错的情况下注释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节点)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆