Javascript 正在侦听器上的firebaseRef.on中等待异步值
我正在研究如何在调用firebase的.set()方法之前等待从异步函数传递的值!这里有一个不起作用的代码Javascript 正在侦听器上的firebaseRef.on中等待异步值,javascript,firebase,firebase-realtime-database,async-await,Javascript,Firebase,Firebase Realtime Database,Async Await,我正在研究如何在调用firebase的.set()方法之前等待从异步函数传递的值!这里有一个不起作用的代码 // main.js firebaseRef.on('value', snap => { if(snap.val()) { otherFirebaseRef.set({ // here i want set the a field with result returned from async function a: (await??)
// main.js
firebaseRef.on('value', snap => {
if(snap.val()) {
otherFirebaseRef.set({
// here i want set the a field with result returned from async function
a: (await??) asyncFunction()
})
}
})
您必须声明函数async
,并执行以下操作:
firebaseRef.on('value', async snap => {
if(snap.val()) {
const theValue = await asyncFunction();
otherFirebaseRef.set({
a: theValue
})
}
})
您必须声明函数async
,并执行以下操作:
firebaseRef.on('value', async snap => {
if(snap.val()) {
const theValue = await asyncFunction();
otherFirebaseRef.set({
a: theValue
})
}
})
@cicciosgamino您好,您有时间查看提议的解决方案吗?@cicciosgamino您好,您有时间查看提议的解决方案吗?