只有当会话变量person
不是null
或不是undefined
时,我才希望在ejs模板中显示dashboard。
但每次都只是显示仪表盘。在我的日志语句中,person
值是undefined
。
<%= console.log(person); %>
<% if (person !== null || person !== undefined) { %>
<%- include("dashboard"); %>
<% } else { %>
<%- include("login"); %>
<% } %>
怎样做才是正确的方法呢?
我不确定,但是你能试着把if语句改成
<% if (person) { %>
如果person不为空或未定义,它将简单地返回true
可以通过以下方式进行:
<%-include(person!==null&person!==未定义?“dashboard”:“login”);%>