LoginSignup
0
0

More than 3 years have passed since last update.

Chrome拡張&FirebaseでのPromise使用例【個人メモ】

Last updated at Posted at 2020-04-17

ポイント
(1)Promiseオブジェクト作成
(2)resolve
(3)then処理
※ご質問受け付けます

var getRoomData = new Promise(function(resolve,reject){  //(1)Promiseオブジェクト作成
    var firebaseConfig = {
    ・・・省略・・・
    };

    // Initialize Firebase
    firebase.initializeApp(firebaseConfig);

    const newPostRef = firebase.database();
    var roomInfo = newPostRef.ref("room");
    roomInfo.on('value', (snapshot)=> {
        resolve(snapshot.val());    ///(2)resolve
    });

})

$(function() {
    getRoomData.then(function(dbData){   //(3)then処理
        // console.log(dbData);
        for(let i in dbData){
            console.log(dbData[i].room_id);
        }

    })
})
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0