【发布时间】:2019-10-06 00:18:58
【问题描述】:
当我尝试更新 Firebase 文档时,它会在console 中显示以下错误消息。
未处理的承诺拒绝 FirebaseError: "Function 使用无效数据调用 DocumentReference.update()。不支持的字段 值:未定义(在字段名称中找到)"
我尝试使用console.log() 进行调试,发现变量editedItem 在更新方法中无法识别。
如何解决这个问题
data: () => ({
editedIndex: -1,
editedItem: {
id: 1,
name: "SSFS",
description: "XXXX"
},
newItem: {
id: null,
name: null,
description: null
}
}),
save() {
if (this.editedIndex > -1) {
// Update Category
// Object.assign(this.desserts[this.editedIndex], this.editedItem);
db.collection('categories').where('id', '==', this.editedItem.id).get().then( (querySnapshot) => {
querySnapshot.forEach( (doc) => {
doc.ref.update({
name : this.editedItem.name,
description : this.editedItem.description
}).then(() => {
this.$router.push('/categories')
})
})
})
}
}
错误:
未处理的承诺拒绝 FirebaseError:“使用无效数据调用函数 DocumentReference.update()。不支持的字段值:未定义(在字段名称中找到)
【问题讨论】:
-
您确定
editedItem对象中有一些值吗?如果你console.log()他们的价值呢?另外,你可以看看stackoverflow.com/questions/48980865/…
标签: javascript firebase vue.js firebase-realtime-database google-cloud-firestore