在下面的代码中,Room.find().exec()
有一个产生变量的回调函数room
。如何访问嵌套回调函数内部的该对象Player.find.exec()
?
addplayer: function(req, res) {
Room.find(req.param('roomid')).exec(function(err, room) {
if (err) {
console.log(err);
return res.send(err, 404);
} else {
if (req.param('playerid') && req.param('playerid').length > 0) {
console.log("Room found:", room);
Player.find(req.param('playerid')).exec(function(err, player) {
if (err) {
console.log(err);
return res.send(err, 404);
} else {
if (typeof room.players === 'undefined' || !room.players.isArray) room.players = new Array();
room.players.push(player);
room.save();
console.log(player);
return res.send(room, 403);
}
});
} else {
console.log('No player id.');
return res.send('No player id.', 404);
}
}
});
}
这让我更容易看到我在问什么: