我想要獲取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-返回異步調用響應,其中詳細解釋了爲什麼無法工作。 –