【发布时间】:2020-05-17 20:23:45
【问题描述】:
saveUsernames(){
let user = firebase.auth().currentUser
db.collection('users').where('user_id',"==", user.uid).get().then(snapshot => {
snapshot.forEach((doc) =>{
for(i=0; i<=this.usernames.length; i++){
db.collection('users').doc(doc.id).update({
name: this.name,
bio: this.bio,
usernamelist:[{Id:i, username: this.usernames[i]}]
})}
})
}).then(() =>{
this.$router.push({ name: "Profile" })
})
我有一组用户名存储在 usernames[] 中,我想存储到我的用户文档中。该索引对应于 Firestore 文档 'users' 中元素 'usernamelist' 中名为 'username' 的元素中相应 Id 值的每个元素的 Id。我将如何循环遍历数据数组中的每个元素并更新 firestore 中的相应元素?我收到一条错误消息,提示“i”未定义。
【问题讨论】:
-
嗨,杰弗里,你能不能更清楚一些!
标签: javascript vue.js google-cloud-firestore