[英]push firebase data inside an array + js + vuejs
I have in firebase firestore
a Collection named users created with docs of unique id.我在
firebase firestore
有一个名为users的集合,该集合使用唯一 ID 的文档创建。
Now I would like to push them in an Array
.现在我想将它们放入
Array
。
(In the usersCollection there are 3 users stored with the currentUser.uid
) (在 usersCollection 中,有 3 个用户存储在
currentUser.uid
)
Example:例子:
fb.usersCollection.where("state", "==", 'online').get().then(querySnapshot => {
querySnapshot.forEach((doc) => {
const userName = doc.data().name
this.markerMy = { name: userName }
})
// push userName inside randomArray
const randomArray = []
randomArray.push(this.markerMy)
I only get it so that I can push one user inside the Array, but not more.我只得到它,以便我可以将一个用户推入 Array 中,但不能推入更多用户。
You should declare randomArray
before fb.usersCollection
and call the push operation inside the callback as follows :你应该申报
randomArray
前fb.usersCollection
回调中并调用推送操作如下:
const randomArray = []
fb.usersCollection.where("state", "==", 'online').get().then(querySnapshot => {
querySnapshot.forEach((doc) => {
const userName = doc.data().name
this.markerMy = {
name: userName
}
randomArray.push(this.markerMy)
})
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.