任何人都可以帮我这个代码吗?我需要从routeToRoom函数返回一个值:
var sys = require('sys');
function routeToRoom(userId, passw) {
var roomId = 0;
var nStore = require('nstore/lib/nstore').extend(require('nstore/lib/nstore/query')());
var users = nStore.new('data/users.db', function() {
users.find({
user: userId,
pass: passw
}, (function(err, results) {
if (err) {
roomId = -1;
} else {
roomId = results.creationix.room;
}
}
));
});
return roomId;
}
sys.puts(routeToRoom("alex", "123"));
Run Code Online (Sandbox Code Playgroud)
但我总是得到:0
我猜return roomId;之前已经执行过了roomId=results.creationix.room.有人可以帮我这个代码吗?