在这里,我正在使用空数组初始化checkedinUsers。我将数组作为参数传递给getCheckedInUsers函数。在firebase db回调中修改了数组checkedinUsers,但是在回调之外的范围内,值不会改变。
var checkedinusers = [];
var getCheckedInUsers = function(checkedinUsers){
database.ref('/checkedin').once('value').then(function(snapshot) {
//console.log(snapshot.val());
if(snapshot.val()!== null){
var temp = snapshot.val();
for(var p in temp){
checkedinUsers.push(temp[p]);
}
console.log(checkedinUsers);
}else{
console.log("No checkedinUsers available");
}
});
console.log(checkedinUsers);
};
getCheckedInUsers(checkedinUsers);