以下のコードで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);
}
}
});
}
これにより、私が何を求めているかを簡単に確認できるようになります。