【问题标题】:How to change values in Hashmap in firestore?如何在firestore中更改Hashmap中的值?
【发布时间】:2019-08-24 11:05:45
【问题描述】:

我在 firestore 中存储一个 hashmap,如下所示:

这是一张数据库图片

问题是当我存储这些值时,我不知道键和值,因为用户正在输入键和值。

如何访问密钥并更改其值?

【问题讨论】:

  • 您想要获取的确切数据是什么?
  • @AlexMamo 工具的所有值也需要更新这些值。
  • 问题解决了吗?

标签: android firebase hashmap google-cloud-firestore


【解决方案1】:

好吧,您可以创建一个额外的元数据字段,在其中记下用户输入的所有键,例如,在一个数组中。它看起来像:

tool {
  metadata: {
    0: "brand_name"
    1: "photo_model"
    ....
  }
  brand_name: "Sony"
  photo_model: "DSLR"
  ...
}

或者您可以以任何其他方式存储它,但重点是,当您获取文档的 dataSnapshot 时,您首先检查这些元数据键,将它们收集到一个数组中,然后您才能构建您的自定义 Bundle 或其他任何东西你的对象看起来像一个循环

【讨论】:

    猜你喜欢
    • 2014-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-11
    • 2015-08-05
    • 2018-08-22
    • 1970-01-01
    相关资源
    最近更新 更多