Just getting started with javascript / express / mongodb. For my initial project, I am working on a simple task manager where todos are categorized by priority - "high," "mid," or "low."
However, I am facing an issue when trying to display different entries on the index page.
The error message states: "tasks_low is not defined"
Here is the relevant javascript snippet:
app.get('/', function(req, res){
db.tasks.find({prio: 'high'}, function (err, highs) {
res.render('index', {
title: 'High Priority Tasks:',
tasks: highs
});
})
});
app.get('/', function(req, res){
db.tasks.find({prio: 'low'}, function (err, lows) {
res.render('index', {
title: 'Low Priority Tasks:',
tasks_low: lows
});
})
});
This is my index.ejs file:
<h1>High Priority</h1>
<ul>
<% tasks.forEach(function(tasks){ %>
<li><%= tasks.task %> <%= tasks.prio %> - <a class="deleteUser" data-id="<%= tasks._id %>" href="#">x</a></li>
<% }) %>
</ul>
<br><br>
<h1>Low Priority</h1>
<ul>
<% tasks_low.forEach(function(tasks_low){ %>
<li><%= tasks_low.task %> <%= tasks_low.prio %> - <a class="deleteUser" data-id="<%= tasks_low._id %>" href="#">x</a></li>
<% }) %>
</ul>
Interestingly enough, everything works well when I compile it into separate views!
app.get('/tasks_high/', function(req, res){
db.tasks.find({prio: 'high'}, function (err, highs) {
res.render('index', {
title: 'High Priority Tasks:',
tasks: highs
});
})
});
app.get('/tasks_low/', function(req, res){
db.tasks.find({prio: 'low'}, function (err, lows) {
res.render('index', {
title: 'Low Priority Tasks:',
tasks_low: lows
});
})
});