1
我想檢索的變量「用戶」之外的功能:檢索的NodeJS一個變量
var users;
client.lrange("comptes", 0, -1, function(err, replies) {
replies.forEach(function(reply, i) {
users = JSON.parse(reply.toString());
});
});
// here to retrieve the "users" variable
console.log(users); // = undefined
function findById(id, fn) {
var idx = id - 1;
if (users[idx]) {
fn(null, users[idx]);
} else {
fn(new Error('User ' + id + ' does not exist'));
}
}
function findByUsername(username, fn) {
for (var i = 0, len = users.length; i < len; i++) {
var user = users[i];
if (user.username === username) {
return fn(null, user);
}
}
return fn(null, null);
}
謝謝你的幫助 。
它的確定:'函數findByUsername(用戶名,FN){ client.lrange( 「審計院」,0,-1,函數(ERR,回覆){ replies.forEach(功能(答覆,我){ users = JSON.parse(reply.toString()); Tusers(users); }); }); 函數對於(var i = 0,len = users.length; i
PixelPixel
2013-05-11 16:21:30