问题描述
我知道如何在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 });
}
很高兴能对此有所启发,谢谢!
解决方法
无法更改数组中的值。您必须 删除旧的值组合并添加新的组合,或必须:
- 阅读文档。
- 从该文档获取整个数组。
- 在应用程序代码中修改数组。
- 将修改后的数组全部写回到数据库中。