如何读取/更新存储在地图中的值,然后将其存储在Cloud Firestore中的数组中? [英] How to read/update values stored inside a map which is then inside of an array in Cloud Firestore?

查看:76
本文介绍了如何读取/更新存储在地图中的值,然后将其存储在Cloud Firestore中的数组中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我是Firestore和Android编程的新手。

To begin with I'm a newbie to Firestore and Android programming.

我有一个存储文档的集合,每个文档包含一个学期数组,学期数组将有一个代表每个学期的地图数组。在各个学期地图中,将有一个数字字段标识该学期,还有一个名为学生的数组,其中将包含一个地图数组,其中每个地图将代表每个学生并存储三个不同的字段:学生的ID,DaysPresent,总计

I have a collection which stores documents, each document contains an array of semesters, inside the semester array there will be an array of maps representing each semester. Inside the individual semester maps, there will be a number field identifying the semester and also another array called Students where it will contain an array of maps where each map will represent each student and store three different fields: ID of the student, DaysPresent, Total.

我试图找到一种方法,以考虑到学期号的方式来读取ID代表的每个学生的数据。

I'm trying to find a way to read the data for each individual student represented by ID in such a way where the semester number is taken into account.

例如,如果用户选择Semester 1,它将进入Semester数组,然后从代表Semester 1的第一个数组中加载值。显示所有代表每个学生的地图,用户可以修改和阅读当前的天数和总数。

For example, if the user selects Semester 1, it will go inside the array Semester and then load up the values from the first array which represents the Semester 1, and it will then display all the maps that represent each student where the days present and the total can be modified and read by the user.

一个关键的要点是总数总是对于每个单独的地图来说都是相同的,这意味着每个单独的学生。

One crucial key point is that the total number will always be the same for every individual map which means every individual student.

推荐答案

编辑:2020年3月26日:

Mar 26th, 2020:

实际上,可以使用以下文章中的解决方案:

Actually it's possible using the solution in the following article:

  • How to map an array of objects from Cloud Firestore to a List of objects?

如果您打算获得 List< Semester> List< Student> 在查询Cloud Firestore数据库时,请注意,目前这是不可能的。即使这些对象的类型为 Semester Student ,也无法将它们映射到Semester列表中/学生对象。要解决此问题,您需要编写代码以迭代这些对象,以便可以将它们从 List< Map> 转换为 List< Semester< List< Student> 。因此,您需要为此应用自己的逻辑。

If you intend to get a List<Semester> or a List<Student> when querying your Cloud Firestore database, please note that this is currently not possible. Even if those objects are of type Semester and Student, there is no way you can map them into a List of Semester/Student objects. To solve this, you need to write code to iterate those objects so you can convert them from a List<Map> to a List<Semester>and List<Student>. So you need to apply your own logic for that.

编辑:

调用时返回的对象类型:

The type of object that is returned when calling:

document.getData();

Map< String Object> ,因此您需要根据逻辑遍历地图并根据需要获取数据。

Is a Map<String Object>, so you need to iterate through the map according to your logic and get the data as needed.

这篇关于如何读取/更新存储在地图中的值,然后将其存储在Cloud Firestore中的数组中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆