嗨,我刚开始使用EJS。现在我需要检查条件,以便在EJS中使用if条件,但是在运行时它会显示错误。我正在尝试的代码是
<script id="insidecontentdata" type="text/x-ejs-template">
<%for(var i=0;i < tooldata.section.length;i++){%>
<% debugger; %>
<div class="conductorHeading">
<%= tooldata.section[i].tittle%>
</div>
<div class="conductorHeadingsub">setting :
<%= tooldata.section[i].settingdepth%>
</div>
<div class="border" style="top:0px;"> </div>
<%if (<%= tooldata.section[i].x_over%>) {%>
<div class="conductorHeadingsub">x-over:
<%= tooldata.section[i].x_over%>
</div>
<%}%>
<%}%>
</script>我可以打印所有的div之前,如果条件,但如果条件是错误的。我的代码有什么问题?
发布于 2016-12-23 13:57:17
在您的if条件下,您使用的是一个表达式<%= tooldata.section[i].x_over%>,它导致了问题。
您已经在脚本中了,所以只需使用普通的JavaScript (如果条件)
<script id="insidecontentdata" type="text/x-ejs-template">
<%for(var i=0;i < tooldata.section.length;i++){%>
<div class="conductorHeading">
<%= tooldata.section[i].tittle%>
</div>
<div class="conductorHeadingsub">setting :
<%= tooldata.section[i].settingdepth%>
</div>
<div class="border" style="top:0px;"> </div>
<%if (tooldata.section[i].x_over) {%>
<div class="conductorHeadingsub">x-over:
<%= tooldata.section[i].x_over%>
</div>
<%}%>
</div>
<%}%>
</script>https://stackoverflow.com/questions/41297384
复制相似问题