gpt4 book ai didi

javascript - 如何在 Angular 或 Angularfirestore 中的 Firestore 上更新()一组 map 对象?

转载 作者:行者123 更新时间:2023-12-04 12:36:59 24 4
gpt4 key购买 nike

我知道如何在 Firestore 中读取和写入文档,但是如何在不删除/删除的情况下更新() map 数组中的值和对象?如果需要,只需更改一个值。
我有一个包含 FormArray 的表单,当价目表上有更新时,它可以进行编辑。

product = {
id: "product id",
brand: "Brand Name",
model: "This is the model of the brand"
lists: [
{ location: "Location 1", price: "0.00" },
{ location: "Location 2", price: "0.00" }
]
}
组件.ts
    export class PageComponent implements OnInit {
productDoc: AngularFirestoreDocument<Product>;
product: Observable<any>;
}

constructor(private afs: AngularFirestore) {}

update() {
this.productDoc.update({ amount: this.updatedProduct });
}
感谢您对它有所启发,谢谢!

最佳答案

无法更改数组中的值。您要么必须删除旧的值组合并添加新组合,要么必须:

  • 阅读文档。
  • 从该文档中获取整个数组。
  • 修改应用程序代码中的数组。
  • 将修改后的数组完整地写回数据库。

  • 或者,您可以将列表存储在映射字段而不是数组字段中,这意味着您可以为每组值指定一个名称 - 您可以使用点符号 update the nested field .

    关于javascript - 如何在 Angular 或 Angularfirestore 中的 Firestore 上更新()一组 map 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63679460/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com