我知道如何在 Firestore 中读取和写入文档,但是如何在不删除/删除的情况下更新() map 数组中的值和对象?如果需要,只需更改一个值。
我有一个包含 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 });
}
感谢您对它有所启发,谢谢!
最佳答案
无法更改数组中的值。您要么必须删除旧的值组合并添加新组合,要么必须:
或者,您可以将列表存储在映射字段而不是数组字段中,这意味着您可以为每组值指定一个名称 - 您可以使用点符号 update the nested field .
关于javascript - 如何在 Angular 或 Angularfirestore 中的 Firestore 上更新()一组 map 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63679460/