【发布时间】:2014-11-12 10:41:19
【问题描述】:
我的控制器中有这段代码从 mongo 检索对象并将其发送到客户端:
index: function(req, res){
List.find({user:req.session.user.id}).exec(function foundLists(error, foundLists) {
if(error) {
return res.json({error:error});
} else {
return res.view({ title:'Lists',lists:foundLists });
}
});
}
在我看来,我会做以下事情:
extends ../layout
block content
.container
p #{lists}
呈现:[object Object],[object Object]
如果我这样做p= JSON.stringify(lists)
它呈现:
[{"user":"546109c0d640523d1b838a32","name":"third","createdAt":"2014-11-11T19:39:36.966Z","updatedAt":"2014-11-11T19:39:36.966Z","id":"546265f83e856b642e3b3fed"},{"user":"546109c0d640523d1b838a32","name":"forth","createdAt":"2014-11-11T19:42:09.268Z","updatedAt":"2014-11-11T19:42:09.268Z","id":"546266913e856b642e3b3fef"}]
我正在努力实现:
#lists
each list in lists
p #{list}
但我收到此错误:
Cannot read property 'length' of undefined
我正在使用 Sails and Jade 1.7.0
【问题讨论】:
-
也让我发疯 :( What did you see?