I am just starting with javascript / express / mongodb. As a little starting project I want to do a simple task manager. The todos should be divided by prios. So every entry has it's flag "high", "mid" or "low".
However, I can't manage to show the different entries on the index page.
The error message is: "tasks_low is not defined"
This is the relevant js snippet:
app.get('/', function(req, res){
db.tasks.find({prio: 'high'}, function (err, highs) {
res.render('index', {
title: 'Aufgaben High:',
tasks: highs
});
})
});
app.get('/', function(req, res){
db.tasks.find({prio: 'low'}, function (err, lows) {
res.render('index', {
title: 'Aufgaben Low:',
tasks_low: lows
});
})
});
This is my index.ejs file:
<h1>Prio High</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>Prio Low</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>
However, when I compile to different views it all works well!
app.get('/tasks_high/', function(req, res){
db.tasks.find({prio: 'high'}, function (err, highs) {
res.render('index', {
title: 'Aufgaben High:',
tasks: highs
});
})
});
app.get('/tasks_low/', function(req, res){
db.tasks.find({prio: 'low'}, function (err, lows) {
res.render('index', {
title: 'Aufgaben Low:',
tasks_low: lows
});
})
});