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