简体   繁体   English

如何在ejs模板中使用if条件

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM