Reputation: 508
Using NodeJS, Express and Sequilize,
I am rendering in my view [object SequelizeInstance:Todo] as oppose to actual data instance value when called with res.render(), however is when called by .send (see commented line below) the data instance value is sent to the view.
exports.test_todo_view = function(req, res) {
return Todo
.findAll({
//attributes: ['id'] //select fields
})
//.then((todos) => res.status(200).send(todos))
.then((todos) => res.render('test/test_view', {layout: 'ca_layout.handlebars', test_data: todos}))
.catch((error) => res.status(400).send(error));
}
Output is[object SequelizeInstance:Todo] for each entry in database.
Can anyone advise? It works ie i can see the data - [{"id":1,"title":"fasdfsd","createdAt":"2017-11-15",...] when i use the .send(todos) as shown.
I am using the below to call the view.
app.get('/test/view', authCarePlan.test_todo_view);
My .handlebars file looks like this
<div>test_data:{{test_data}}</div>
where i want the query output to come through as test_data
Upvotes: 1
Views: 835
Reputation: 508
The following config was required in the .handlebars view
{{#test_data}}
{{title}}
{{/test_data}}
Where test_data is the name of the variable placeholder and title is name of a field within it.
Upvotes: 1