firebase firestore在运行时更新变量嵌套数据

Qrow Saki

如何更新直到运行时才确定的嵌套值?

例如,我希望更新作为用户ID的键上的值。我不知道要更新哪个用户,直到运行时。

文档提供了以下示例代码(https://firebase.google.com/docs/firestore/manage-data/add-data#update_fields_in_nested_objects):

db.collection("users").doc("frank").update({
    "age": 13,
    "favorites.color": "Red"
})

我已经使用模板文字修改了它以适合我的目的:

db.collection("chatGroups").doc(route.params.data.id).update({
    `markedDates.${auth.currentUser.uid}`: markedDates
});

但是会引发语法错误。

多米尼克

对动态对象键使用括号符号

db.collection("chatGroups").doc(route.params.data.id).update({
    [`markedDates.${auth.currentUser.uid}`]: markedDates
});

它的规格在这里:https : //www.ecma-international.org/ecma-262/6.0/#sec-object-initializer

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章