【发布时间】:2019-01-15 01:13:20
【问题描述】:
在Firebase Firestore中创建数组需要哪些代码?
我要存储userDetails:
userName: this.userProfile.name,
userImage: this.userProfile.image,
userId: this.userProfile.userId
作为Firestore内的数组
Vue组件:
...
data () {
return {
postDetails: {
createdOn: new Date(),
content: '',
userId: null,
image: null,
comments: 0,
likes: 0,
userDetails: []
}
userData: [
{ userName: this.userProfile.name },
{ userImage: this.userProfile.image},
{ userId: this.userProfile.userId }
}
},
methods: {
createPost () {
fb.postsCollection.add({
createdOn: this.postDetails.createdOn,
content: this.postDetails.content,
userId: this.currentUser.uid,
image: this.postDetails.image,
comments: this.postDetails.comments,
likes: this.postDetails.likes
userData: this.userData
}).then(ref => {
this.post.content = ''
this.$router.push('/dashboard')
}).catch(err => {
console.log(err)
})
}
}
【问题讨论】:
-
您的文档中已经有两个数组:tags 和 userData。我根本不清楚你遇到了什么问题。
-
是的,但我在 firebase 控制台中手动添加了两者
-
我不知道如何用代码做到这一点
-
您是否尝试过将一个包含一些数据的 JavaScript 数组实际放入您的代码中?
-
是的,但在 Firestore 中,它的输出就像普通字符串一样
标签: javascript firebase vue.js google-cloud-firestore