如何在 Angular 或 Angularfirestore 中的 Firestore 上更新()一组地图对象? [英] How to update() an array of maps-objects on Firestore in Angular or Angularfirestore?

查看:29
本文介绍了如何在 Angular 或 Angularfirestore 中的 Firestore 上更新()一组地图对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I know how to READ and WRITE a document in Firestore, But how does one update() a Value of and object in an array of Maps without removing/deleteing? Just changing one value if needed.

我有一个包含 FormArray 的表单,当价目表有更新时,它可以编辑为一个.

I have a Form that includes a FormArray, that are able to edit as an when there is an update on the price list.

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 });
  }

感谢照亮它,谢谢!

推荐答案

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

There is no way to change a value in an array. You'll either have to remove the old combination of values and add the new combination, or have to:

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

这篇关于如何在 Angular 或 Angularfirestore 中的 Firestore 上更新()一组地图对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆