【问题标题】:How to update() an array of maps-objects on Firestore in Angular or Angularfirestore?如何在 Angular 或 Angularfirestore 中的 Firestore 上更新()一组地图对象?
【发布时间】:2020-12-20 02:00:54
【问题描述】:

我知道如何在 Firestore 中读取和写入文档,但是如何在不删除/删除的情况下更新()地图数组中的值和对象?如果需要,只需更改一个值。

我有一个包含 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 });
  }

感谢您给它一些启发,谢谢!

【问题讨论】:

    标签: javascript angular firebase google-cloud-firestore angularfire


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-01-31
      • 2020-03-02
      • 2021-02-02
      • 2014-05-23
      • 2021-03-26
      相关资源
      最近更新 更多