如何在ejs中使用if语句? [英] How can I use if statement in ejs?
本文介绍了如何在ejs中使用if语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个页面进行foreach并显示一些类似这样的照片
I have a page that makes a foreach and show some photos like this
<% imgs.forEach(function(img) { %>
<img src="uploads/<%=user.username%>/screenshots/<%= img %>">
<% }); %>
我想做一个if语句,因为如果没有照片显示会给出这样的消息:
And I want make a if statement because, in case that not photos to show gives a message like this:
没有照片上传
"no photos uploaded"
推荐答案
类似这样的东西:
<% if(imgs.length > 0){ %>
<% imgs.forEach(function(img) { %>
<img src="uploads/<%=user.username%>/screenshots/<%= img %>">
<% }); %>
<% } else{ %>
<p>no photos uploaded</p>
<% } %>
这篇关于如何在ejs中使用if语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文