Reputation: 731
I am trying to pass the query result to a handlebars page. The query result is taken as shown below:
connection.query("select * from members",function(err,rows){
connection.release();
if(!err) {
var data = rows; //tried JSON.stringify, JSON.parse, both
console.log(data);
/*
[{"username":"[email protected]","manager_id":"one"},
{"username":"[email protected]","manager_id":"two"},
{"username":"[email protected]","manager_id":"three"}]
*/
res.render('handlebarsPage',{data:data});
}
}
However in the handlebarsPage, I cannot access the data using:
{{data[0].username}} // Parse Error
Please suggest the right way to achieve this in handlebars
<%= data[0].username %> // works fine in ejs
Upvotes: 0
Views: 2322
Reputation: 693
Try one of the following:
{{data.[0].username}} or
{{data.0.username}}
Upvotes: 2