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

问题描述

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

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的Form,可以在价目表上进行更新时进行编辑.

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

Component.ts

Component.ts

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

constructor(private afs: AngularFirestore) {}

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

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

Appreciate to shine some light on it, Thank You!

推荐答案

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

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上更新()一组地图对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 07:00