有最奇怪的问题。 我无法显示对象的email属性。 我正在使用Mongoose / Express / Jade。 我正在做一个:
User.find({ _id : { $in : req.project.subscribers } } , function (err, subs){...这工作得很好,并返回subs var中的我的订阅者列表,如下所示:
{ _id: 4f34832b9398bec847000002, email: 'steve@example.com', first_name: 'Steve', last_name: 'McQueen', status: 'active', username: 'steve', updated_at: Fri, 10 Feb 2012 02:38:35 GMT, created_at: Fri, 10 Feb 2012 02:38:35 GMT, role: 'subscriber' }, { _id: 4f3484a9eceb82b548000002, email: 'paul@example.com', first_name: 'Paul', last_name: 'Stanley', status: 'active', username: 'paul', updated_at: Mon, 02 Apr 2012 15:09:56 GMT, created_at: Mon, 02 Apr 2012 15:09:56 GMT, role: 'subscriber' }然后我通过一个名为订阅者的var将它传递给我的玉石视图。 所有这一切都很好,当我在我的玉模板中遍历subscribers者时,我想要显示每个订户的email属性时,问题就出现了。 由于某种原因,这只是email的问题! 它没有显示任何email ,只是空白。
ul each sub in subscribers li= sub.email如果我用任何其他属性代替email它工作正常。 所以以下显示非常好:
ul each sub in subscribers li= sub.username请让我知道,如果我可以提供更多的细节。
编辑Declan:
执行以下操作:
ul each val, key in subscribers li #{key}: #{val}产量:
0: { _id: 4f34832b9398bec847000002, email: 'foo', first_name: 'Steve', last_name: 'McQueen', status: 'active', username: 'steve', updated_at: Fri, 10 Feb 2012 02:38:35 GMT, created_at: Fri, 10 Feb 2012 02:38:35 GMT, role: 'subscriber' } 1: { _id: 4f3484a9eceb82b548000002, email: 'foo', first_name: 'Paul', last_name: 'Stanley', status: 'active', username: 'paul', updated_at: Mon, 02 Apr 2012 16:05:51 GMT, created_at: Mon, 02 Apr 2012 16:05:51 GMT, role: 'subscriber' }Having the strangest problem. I can't display the email property of an object. I'm using Mongoose/Express/Jade. I'm doing a:
User.find({ _id : { $in : req.project.subscribers } } , function (err, subs){...Which works just fine and returns a list of my subscribers in the subs var that looks like so:
{ _id: 4f34832b9398bec847000002, email: 'steve@example.com', first_name: 'Steve', last_name: 'McQueen', status: 'active', username: 'steve', updated_at: Fri, 10 Feb 2012 02:38:35 GMT, created_at: Fri, 10 Feb 2012 02:38:35 GMT, role: 'subscriber' }, { _id: 4f3484a9eceb82b548000002, email: 'paul@example.com', first_name: 'Paul', last_name: 'Stanley', status: 'active', username: 'paul', updated_at: Mon, 02 Apr 2012 15:09:56 GMT, created_at: Mon, 02 Apr 2012 15:09:56 GMT, role: 'subscriber' }I then pass that to my jade view in a var called subscribers. All good to this point, the problem arises when I want to display the email property of each subscriber when I iterate over subscribers in my jade template. It's only a problem with email for some reason! It doesn't show anything for email, just blank.
ul each sub in subscribers li= sub.emailIt works fine if I substitute ANY of the other properties in place of email. So the following displays perfectly fine:
ul each sub in subscribers li= sub.usernamePlease let me know if I can supply any more detail.
EDIT for Declan:
Doing the following:
ul each val, key in subscribers li #{key}: #{val}Yields:
0: { _id: 4f34832b9398bec847000002, email: 'foo', first_name: 'Steve', last_name: 'McQueen', status: 'active', username: 'steve', updated_at: Fri, 10 Feb 2012 02:38:35 GMT, created_at: Fri, 10 Feb 2012 02:38:35 GMT, role: 'subscriber' } 1: { _id: 4f3484a9eceb82b548000002, email: 'foo', first_name: 'Paul', last_name: 'Stanley', status: 'active', username: 'paul', updated_at: Mon, 02 Apr 2012 16:05:51 GMT, created_at: Mon, 02 Apr 2012 16:05:51 GMT, role: 'subscriber' }最满意答案
我回答我自己的问题,因为它最终变得愚蠢而明显(通常是,不是吗?)。
当使用猫鼬并且不显示属性时,请确保您拥有在猫鼬模式中定义的属性。 不知何故,当我创建我的模式时,我忽略了电子邮件字段,并且它没有被定义。 即使它在数据库中的实际记录中,猫鼬也不在乎,只会向您显示您为对象/模式定义的内容。
感谢大家的努力,如果没有别的,你帮我找到我的答案。
I'm answering my own question because it ended up being something stupid and obvious (usually is, isn't it?).
When using mongoose and a property doesn't show up, be sure that you have that property defined in your mongoose schema. Somehow, I overlooked the email field when I created my schema and it just wasn't defined. Even though it was in the actual record in the DB, mongoose doesn't care and will only show you what you've defined for the object/schema.
Thanks to everyone for your efforts, if nothing else, you helped me get to my answer.
更多推荐
发布评论