![](/img/trans.png)
[英]Meteor Blaze helper and Mongo collection.find with Session key selector
[英]Handlebar template access to mongo collection.find() variable in a nodejs
我有如下的nodejs express脚本
app.get('/approval',function(req,res){
db.open(function(err,db) {
var collection = db.collection('form');
collection.find({ contact: 'James Wong' }).toArray(function(err, docs) {
console.log(docs);
/*It will will give an output something like
{ _id: 53533045fec60bd941c04a22,
contact: 'James Wong'} */
res.render('approval.handlebars',{resultfind : docs});
/*it will give an output as [object Object]
db.close();
});
});
我的console.log(docs)输出为JSON ARRAY格式,这是正确的。 即
{ _id: 53533045fec60bd941c04a22,
contact: 'James Wong'} */
但是,当我使用res.render在handlebartemplate中显示它时,结果将如下所示;
[object Object]
我的模板在下面
<div>
{{resultfind}}
</div>
我想访问那些对象属性。
解决了..感谢TheShellfishMeme。
两件事要做
1)代替toArray函数,将其替换为每个函数。 这是为了保持json格式
2)通过html {{resulfind.contact}}访问JSON格式
干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.