本文介绍了如何在Firestore上打破querySnapshot?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要打破querysnapshot循环.有可能吗?
I need to break querysnapshot loop. Is it possible?
我尝试了for循环.但是出现以下错误.
I tried with for loop. but the below error is coming.
如何解决此错误,或者有什么方法可以打破快照循环?
How to fix this error or Is there any way to break snapshot loop?
代码
return query.get()
.then((snapshot) => {
for(const doc of snapshot) {
let data = doc.data()
if (data.age == 16) {
break;
}
}
错误
推荐答案
您可以使用 QuerySnapshot的 docs
属性,该属性返回QuerySnapshot中所有文档的数组.
You can use the docs
property of the QuerySnapshot, which returns an array of all the documents in the QuerySnapshot.
例如,带有for循环:
For example, with a for loop:
return query.get()
.then((snapshot) => {
const snapshotsArray = snapshot.docs;
for (var i = 0; i < snapshotsArray.length; i++) {
const data = snapshotsArray[i].data()
if (data.age == 16) {
break;
}
}
}
或带有 for :
return query.get()
.then((snapshot) => {
const snapshotsArray = snapshot.docs;
for (const snap of snapshotsArray) {
const data = snap.data()
if (data.age == 16) {
break;
}
}
}
这篇关于如何在Firestore上打破querySnapshot?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!