这怎么能等到更新完成后再移动到下一个项目呢?
How can this wait until the update is finished to move to the next item?
我想让它等到。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 */);
}
}
可能是这样的。
let {players} = this.props;
let p = Promise.resolve(); // just really want a promise to start
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) {
p = p.then(()=>{
return window.firebase.database().ref(`/players/${firebaseId}`)
.update({...player}, /* Callback possible */);
});
}
}
这从一个已解决的承诺开始,这将导致第一个更新立即执行。
相关文章:
- 简单的垂直上一个和下一个按钮代码点击上下移动jQuery
- JQuery insertAfter();移动下一个表格单元格
- 我们如何捕捉移动设备“;下一个“;在Javascript中按键
- 如何移动到数组的上一个/下一个索引键
- 字段验证器,它不允许移动到下一个字段
- 当一个字段已满时,将数据条目移动到下一个字段-JS制表
- 更改移动到phonegap中的下一个活动的风格-移动android
- 在动态创建的输入上使用向下箭头键将光标移动到下一个输入
- Jquery方法选择,用于移动到下一个父子
- 确定 Javascript 中图像轮播的下一个正确移动
- 如何在使用angularjs选项卡时单击按钮移动到下一个选项卡
- 如何在测验应用中移动到下一个或上一个问题
- 如果用户不更改该选项,请将焦点移动到下一个字段
- 如果不在表单中填写一个字段,我的光标不应该移动到 javascript 验证中的下一个字段
- 如果删除了 localStorage 密钥,请将所有下一个密钥移动 1 位
- AngularJS:单选按钮在移动到下一个部分后失去价值
- 选择1后无法切换以移动到下一个案例
- 花式框下一个和上一个按钮在移动设备上不起作用
- 当移动到最后一个li时,返回到第一个li(使用Jquery滚动到下一个)
- Javascript下拉菜单移动到下一个“;阶段”;