最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use if statement in ejs with strings? - Stack Overflow

programmeradmin2浏览0评论

I have a page that - If demo.text is 'disabled' than disabled demo button else enabled demo button.

index.ejs

<% for(project of projects) { %>
   <a class="info" href="#"> 
<% if(project.demo == 'disabled') { %>
   <button class="btn btn-primary" disabled> Button1 </button>
<% } else { %>
  <button class="btn btn-primary"> Button1 </button>
 </a>
<% } %>`

app.js

app.get('/', (req, res) => {
res.render('index', {
    projects: [
        { demo: 'disabled' },
        { demo: '' }
    ]
  });
});

I have a page that - If demo.text is 'disabled' than disabled demo button else enabled demo button.

index.ejs

<% for(project of projects) { %>
   <a class="info" href="#"> 
<% if(project.demo == 'disabled') { %>
   <button class="btn btn-primary" disabled> Button1 </button>
<% } else { %>
  <button class="btn btn-primary"> Button1 </button>
 </a>
<% } %>`

app.js

app.get('/', (req, res) => {
res.render('index', {
    projects: [
        { demo: 'disabled' },
        { demo: '' }
    ]
  });
});
Share Improve this question asked Nov 27, 2017 at 10:40 Pradip DhakalPradip Dhakal 1,9621 gold badge14 silver badges31 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

while using EJS Template engine opening and closing should be correct. for further references http://ejs.co/#docs

 <% for(project of projects) { %>
      <a class="info" href="#"> 
         <% if(project.demo == 'disabled') { %>
              <button class="btn btn-primary" disabled> Button1 </button>
         <% } else { %>
             <button class="btn btn-primary"> Button1 </button>
         <% } %>
     </a>
<%}%>
发布评论

评论列表(0)

  1. 暂无评论