0
我在此处使用Node,并将以下函数用作控制器操作。我使用Mongoose来访问模型,并且在Game.findById()的范围内,我无法访问它上面的任何变量,即this.player和this.gameId。使用Mongoose和Node.js进行JavaScript范围界定问题
有谁知道我做错了什么?请注意,我想访问console.log()语句所在的变量,但我无法访问它。 this.player返回undefined。在此先感谢您的帮助。
exports.cleanup = function(req, res) {
this.player = req.body;
this.gameId = req.url.split('/')[2];
debugger;
Game.findById(this.gameId, function(err, game) {
if (err) return err;
console.log(this.player);
});
};