[英]How to use if condition in ejs template
Server Code服务器代码
Details['11'] = {
'id': '11',
'name': 'Avanish'
};
res.render('/index',{'Message': Details});
Page code页面代码
<script>
var ERRORCONST = 'Error';
var NORECORDS = 'No records';
</script>
<%if(Message != undefined && Message != NORECORDS && Message != ERRORCONST ){%>
<%Message.forEach(function(key){%>
<span><%= key.id %> - <%= key.name %></span>
<%});%>
<%}%>
Getting error NORECORDS is not defined
and print all code on page.获取错误
NORECORDS is not defined
并在页面上打印所有代码。 I have two error.我有两个错误。 One is how to use Multiple condition in single if statement and second is how to compare
javascript
varibale with server variable一是如何在单个 if 语句中使用多个条件,二是如何将
javascript
变量与服务器变量进行比较
<% var ERRORCONST = 'Error';
var NORECORDS = 'No records'; %>
In ejs template
please use constant like this.在
ejs template
请使用这样的常量。
You can not compare ejs
variable and local script variable.您无法比较
ejs
变量和本地脚本变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.