如何在Angular或Angularfirestore的Firestore上更新一组地图对象?

问题描述

我知道如何在Firestore中读取和写入文档,但是如何在不删除/删除的情况下更新()一个Map数组中的value和object?只需更改一个值即可。

我有一个包含FormArray的Form,可以在价目表上有更新时进行编辑。

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" }
  ]
}

Component.ts

    export class PageComponent implements OnInit {
      productDoc: AngularFirestoreDocument<Product>;
      product: Observable<any>;
    }

constructor(private afs: AngularFirestore) {}

  update() {
    this.productDoc.update({ amount: this.updatedProduct });
  }

很高兴能对此有所启发,谢谢!

解决方法

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

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

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...