firebase - 如何在'Firestore DocumentSnapshot'的for循环中只调用一次函数?
问题描述
我正在尝试从firestore
使用中删除文档:
FirebaseFirestore.instance
.collection("Data")
.where('user_id', isEqualTo: uid)
.get()
.then((snapshot) {
for (DocumentSnapshot ds in snapshot.docs) {
ds.reference.delete().then((value) {
print("document deleted");
moveToNextDeletion(); // <-The function shold be called only once
});
}
});
因此,一旦删除了所有文档,我就想调用moveToNextDeletion();
函数,但它会一直调用,直到所有文档都被删除(导致 for 循环)。
删除所有文档后,有什么方法可以调用该函数?
解决方案
使用while循环而不是for循环希望它会起作用
推荐阅读
- asp.net-mvc - 将参数值从动作结果传递到同一控制器中的另一个
- python-3.x - 无法使用来自 fancyimputer (Python) 的 MICE
- php - 如何修复 iOS 无线企业应用程序安装不显示应用程序图标
- java - 可由它创建的实例访问的实例
- react-native - 可能未处理的承诺拒绝(id 0)类型错误 this.setstate 不是函数
- java - 如何使用mybatis接口而不是sqlSession处理地图结果(两列结果)
- c# - Botframework v4:无法渲染卡片
- python - 粘性命令如何影响 Tkinter 中的 python 代码?
- java - JFreeChart 不起作用并阻止我的代码
- php - 如何获取当前经过身份验证的用户?