Here is the code... I am trying to only display items with a certain class on the dashboard:
<% newListItems.forEach(function(item){ %>
<% if (currentClasses.includes(item.class) { %>
<div class="item">
<input type="checkbox">
<p class="ptag"><%= item.name %></p>
</div>
<% }) %>
<% }) %>
Here is the app.js code for some reference
app.get("/todolist", function (req, res) {
if (req.isAuthenticated()) {
const currentClasses = req.user.classes
Item.find({}, function (err, foundItems) {
if (foundItems.length === 0) {
Item.insertMany(defaultItems, function (err) {
if (err) {
console.log(err)
} else {
console.log("Success!")
}
})
res.redirect("/todolist")
} else {
console.log(currentClasses)
res.render("todolist", { newListItems: foundItems })
}
})
} else {
res.redirect("/login")
}
});
I don't know why the EJS code is giving an unexpected token { error because the brackets and parenthesis seem to add up
<% newListItems.forEach(function(item){ %>
<% if (currentClasses.includes(item.class)) { %>
<div class="item">
<input type="checkbox">
<p class="ptag"><%= item.name %></p>
</div>
<% } %>
<% }) %>
You were closing the parenthesis for the if
statement in the penultimate line
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.