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

标签 javascript angular firebase google-cloud-firestore angularfire

我知道如何在 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/

    相关文章:

    javascript - 如何在用户放大和缩小页面时保持 <div> 的大小不变?

    javascript - Angularjs,指令,符号

    javascript - TypeScript基础编程: interface issue

    android - 如何使用数据绑定(bind)库将 Firebase 监听器转换为可观察 map ?

    swift - 如何向 Firebase 数组添加另一个键/值

    javascript - 正则表达式与 while 循环

    angular - 在 Angular 中,spyOn 无法使用异步管道

    javascript - 尝试将 URL 传递到 Iframe Src Angular 2 时出现错误

    firebase - 具有电子邮件和密码身份验证的Firebase Dart

    javascript - 使图像卷轴中的图像成为可点击的链接