運用firebase 的範例可以讀取數據庫的資料,但能不能把var foodn1轉換成全域函數
const foodn = firebase.database().ref("eat").child('nn');
foodn.on('value', snap =>{var foodn1=snap.val();console.log(foodn1);});
結果
var foodn1;
const foodn = firebase.database().ref("eat").child('nn');
foodn.on('value', snap =>{foodn1=snap.val();console.log(foodn1);});
console.log(foodn1);
結果foodn1是undefined
所以只能把運算式放進這嗎?
foodn.on('value', snap =>{foodn1=snap.val();});