Flutter获取子集合

huangapple go评论68阅读模式
英文:

flutter fetching sub-collections

问题

我想获取子集合的名称、长度和它们的文档。
思路如下:我想创建一个ListViewBuilder,其itemcount是子集合的长度(在此示例中为2,如照片中所示),并且我需要让每一个子集合都可以在每一个绿色按钮上访问。例如,我需要名为"day 1"的子集合作为第一个按钮的名称,当我点击该按钮时,它将显示所有文档,与第二个子集合相同。如何使用代码实现这一点?

英文:

i want to fetch sub-collections names, length and their docs.
the idea is as follow: i want to create ListViewBuilder that its itemcount is the length of sub collections (which is 2 in this case as shown in the photo) and i need each one of sub collection would be accessed in each one of the green buttons. for example: i need the sub-collection named "day 1" would be the name of the first button, and when i click on the button... it will show me all its documents, same as the second sub-collection. how to implement that with code?

Flutter获取子集合
Flutter获取子集合

is there a way to do that ?

答案1

得分: 1

代码部分不需要翻译,以下是翻译好的内容:

"First The days should be documents instead of sub-collections if there is going to be only 1 document in each of them.

With firebase there is a function called collectionGroup("collection name") its job is to get all sub-collections in your Firestore with a certain name, to use it in your case do like this:

FirebaseFirestore.instance.collectionGroup("week 1").get();

This line will give you the documents of the collection week 1 in all other collections.

For more on collectionGroup, check this blog: collectionGroup blog

英文:

First The days should be documents instead of sub-collections if there is going to be only 1 document in each of them.

With firebase there is a function called collectionGroup("collection name") it's job is to get all sub-collection in your firestore with a certain name, to use it in your case do like this:

FirebaseFirestore.instance.collectionGroup("week 1").get();

this like will give you the documents of the collection week 1 in all other collections.

more on collectionGroup check this blog: collectionGroup blog

huangapple
  • 本文由 发表于 2023年3月9日 19:35:29
  • 转载请务必保留本文链接:https://go.coder-hub.com/75684055.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定