-2

始终返回未定义的值(此处为 user.password)。我真的不明白为什么

var userModel = restful.model('user');
userModel.find({email:req.params.email}, function(err, user){
    if (user.length){
      console.log(user); // WORKS WELL. I see whole object
      console.log(user.password); // Retuns undefined
      res.render(viewPath + "accountVerified", { meta: meta, success:1});
    }
});
4

1 回答 1

0

您正在从 db 加载多条记录,但试图从数组中访问变量。查看编辑的代码:

var userModel = restful.model('user');
userModel.find({email:req.params.email}, function(err, users){
    if (users.length) {
      console.log(users); // WORKS WELL. I see whole object
      console.log(users[0].password); // Retuns undefined
      res.render(viewPath + "accountVerified", { meta: meta, success:1});
    }
});
于 2013-07-15T15:23:47.577 回答