简体   繁体   中英

SequelizeInstance object not rendering in Express Handlebars view (NodeJS, Express)

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM