第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將輔助數(shù)據(jù)傳遞給我的第二個回調(diào)函數(shù)

將輔助數(shù)據(jù)傳遞給我的第二個回調(diào)函數(shù)

泛舟湖上清波郎朗 2021-11-04 16:27:38
我想在我的第二個回調(diào)中使用變量中間數(shù)據(jù),但我不知道在我目前的情況下如何將它傳遞到那里。有人知道怎么做嗎?   const unsubscribe = firebase     .locations()     .once('value')     .then(async snapshot => {       const promises = []       const intermediateData = snapshot.val()       snapshot.forEach(element => {         promises.push(firebase.user(element.key).once('value'))       })       return Promise.all(promises)     })     .then(snapshots => {       const userInformation = []       snapshots.forEach(userSnapshot => {         if (userSnapshot.exists()) {           userInformation.push({             userId: 1,             name: userSnapshot.val().username           })         }       })     })   return () => unsubscribe }, [firebase, setSnackbarState, userId]) ```
查看完整描述

2 回答

?
慕工程0101907

TA貢獻1887條經(jīng)驗 獲得超5個贊

您可以返回一個包含Promise.all結(jié)果的對象和intermediateData


const unsubscribe = firebase

  .locations()

  .once('value')

  .then(async snapshot => {

      const promises = []

      const intermediateData = snapshot.val()


      snapshot.forEach(element => {

        promises.push(firebase.user(element.key).once('value'))

      })


      return Promise.all(promises).then(snapshots => ({snapshots, intermediateData})

                                                      // ^^ return object

      })

    .then(({snapshots, intermediateData}) => {

           // ^^^ destructure returned object

      const userInformation = []


      snapshots.forEach(userSnapshot => {

        if (userSnapshot.exists()) {

          userInformation.push({

            userId: 1,

            name: userSnapshot.val().username

          })

        }

      })

    })


查看完整回答
反對 回復(fù) 2021-11-04
?
收到一只叮咚

TA貢獻1821條經(jīng)驗 獲得超5個贊

將其放在外封口中:


let intermediateData;

const unsubscribe = firebase

 .locations()

 .once('value')

 .then(async snapshot => {

   const promises = []

   intermediateData = snapshot.val()


   snapshot.forEach(element => {

     promises.push(firebase.user(element.key).once('value'))

   })


   return Promise.all(promises)

 })

 .then(snapshots => {

   //

   // Now you can access intermediateData here

   //

   // ...

 })


查看完整回答
反對 回復(fù) 2021-11-04
  • 2 回答
  • 0 關(guān)注
  • 197 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號