I only want to show dashboard in my ejs template when my session variable person
is not null
or not undefined
.
But it's just showing the dashboard every time. and in my log statement, the person
value is undefined
.
<%= console.log(person); %>
<% if (person !== null || person !== undefined) { %>
<%- include("dashboard"); %>
<% } else { %>
<%- include("login"); %>
<% } %>
What could be the proper way to do it?
I'm not sure but can you try changing the if statement to
<% if (person) { %>
It will simple return true if person is not null or undefined
它可以通过以下方式完成:
<%- include(person !== null && person !== undefined ? "dashboard" : "login"); %>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.