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

编程入门 行业动态 更新时间:2024-10-27 05:26:06
本文介绍了如何在 Angular 或 Angularfirestore 中的 Firestore 上更新()一组地图对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我知道如何在 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:

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

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

更多推荐

[db:关键词]

本文发布于:2023-04-22 11:07:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1023084.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   地图   如何在   Angularfirestore   Angular

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!