I am trying to build a checklist app that takes input from a form and then writes it to a collection. The problem is that, when I try to print the input on the same page I took it from, it does not reach the JavaScript in the html.
If I console.log(checklist_data);, I see all the data from mongo. How do I get it to the page?
routes/index.js:
//insert into the db ( works perfectly)
var mongoose = require('mongoose');
var checklist_model = mongoose.model('checklist_model');
exports.create = function (req, res) {
new checklist_model({
name: req.body.name,
comment: req.body.comment
}).save(function (err, checklist_model) {
res.redirect('/checklist');
});
// query db for all checklist items ( checklist_data has all the data )
exports.checklist = function (req, res) {
checklist_model.find(function (err, checklist_data, count) {
res.render('checklist', {
title: 'checklist',
checklist_data: checklist_data
});
console.log(checklist_data);
});
};
}
HTML:
//HTML code
<script language="javascript" class="lookhere">
checklist_data.forEach( function( checklist_model ){
checklist_model.content
});
</script>
app.js:
app.get('/', routes.index);
app.get('/checklist', routes.checklist);
app.post('/create', routes.create);