我想要获取Firebase中某个函数以外的值,以便在全局范围内使用,但它不起作用。从firebase获取价值
var ref = new Firebase("https://xxxxx.firebaseio.com/users/xxxx/roles/admin/"); // true or false
ref.once("value", function(snapshot) {
console.log("here");
console.log(snapshot.val());
var isAdmin = snapshot.val();
return isAdmin;
});
console.log(isAdmin); /// cannot get value
另见:http://stackoverflow.com/questions/14220321/how-do-i-返回异步调用响应,其中详细解释了为什么无法工作。 –