【发布时间】:2017-01-19 10:05:11
【问题描述】:
我希望它等到 .update() 完成后再转到 otherPlayers 数组中的下一个玩家。我不知道发电机或其他东西是否可以在这里工作。
let {players} = this.props;
for(let player of otherPlayers) {
const index = players.findIndex(p => p.Id === player.Id);
const firebaseId = index && players[index].firebaseId;
if(index !== -1 && firebaseId !== null) {
window.firebase.database().ref(`/players/${firebaseId}`)
.update({...player}, /* Callback possible */);
}
}
【问题讨论】:
-
我想你可以在here找到答案。
-
你在代码中使用 ES6 和 babel,因为你可以使用
await函数让更新等待完成。 -
我确实使用 ES6 和 babel。
标签: javascript asynchronous firebase firebase-realtime-database generator