Reputation: 634
What am I doing wrong?
test.jade
doctype !!! 5
html(lang="en-us")
head
title test
h1 Information;
body
block testcontent
form(method="post")
input(type="button", value="refresh")
testcontent.jade
extends test
append testcontent
br
p test #{title}
routing handler;
app.get('/search', function(req, res) {
res.render('test');
});
app.post('/search', function(req, res) {
table.find().sort({created:1}).toArray(function(err, items) {
if(err) {
console.log(err);
}
else {
res.render('testcontent', {title:items._id});
}
});
});
Trying to make it write 'test' and the title for each item in my database. I click 'refresh' in the page, nothing happens.
When the user sends a POST using the refresh button, it's meant to get every entry's _id in my database and stick it in an array with table.find().sort({created:1}).toArray()
Then I wanted it to render testcontent for each entry, res.render('testcontent', {title:items._id}); which should push out several entries of "test exampleTitle" on new lines.
Then that goes into the testcontent block in the first file, which can now be 'updated' every time the user clicks refresh.
Right?
But it doesn't work, no errors thrown, it just doesn't add the "test title" text to the /search route like I want it to.
I'm using Node.js/express and MongoDB.
Upvotes: 0
Views: 66
Reputation: 1457
Did you check if your form is submitted? Change the type of the button to submit from button and that will submit the form. And in your route handler, I see you are passing only one title to your template, so you will see only one line in your page. If you want one line per entry, you should pass the whole array to your template and iterate using the 'each' construct in your jade template
Upvotes: 1