【发布时间】:2018-09-11 02:29:10
【问题描述】:
如果 EJS 文件上没有博客文章,我正在尝试使用占位符...
如果数据库中有项目,一切正常,但我无法让 if else 语句正常工作。这是我得到的:
<% if (typeof posts != undefined || posts.length >= 2) { for (var i = posts.length - 1; i > posts.length - 3; i--) { %>
<a class="post-link" href="/posts/<%= posts[i]._id %>">
<div class="post-body">
<div class="post">
<div class="post__heading">
<h2 class="heading-secondary"><%= posts[i].title %></h2>
</div>
<div class="post__content">
<p><%= posts[i].body.slice(0, 800) %>...</p>
</div>
<div class="date">
<span class="heading-secondary-date">
<%= posts[i].date %>
</span>
</div>
</div>
</div>
</a>
<% } } else { %>
<h1>There is nothing here</h1>
<% } %>
我一定是做错了什么,因为 EJS 无法识别 if else 语句。
任何帮助将不胜感激。
谢谢,
拉夫
【问题讨论】:
标签: node.js mongodb express mongoose ejs