Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
479 views
in Technique[技术] by (71.8m points)

flutter - 使用Flutter Firestore插件,对文档中的每个子集合进行操作(Using Flutter Firestore plug in, do something for each sub collection in a document)

To help me better understand Flutter and Firebase, I'm making a list sharing app.

(为了帮助我更好地理解Flutter和Firebase,我正在制作一个列表共享应用程序。)

I'm working on the list home screen that will show a reorderable list tile view with a tile for each of the users' lists, I have not began to work on whats inside of these lists.

(我正在使用列表主屏幕,该屏幕将显示一个可重新排序的列表图块视图,其中包含每个用户列表的图块,但我尚未开始研究这些列表中的内容。)

I have firestore set up so that each list is a sub collection, now I want to create a tile for each sub collection in that user's document ( a list of that user's lists).

(我设置了Firestore,以便每个列表都是一个子集合,现在我想为该用户文档中的每个子集合(该用户列表的列表)创建一个磁贴。)

I'm having a tough time telling flutter to do something for each sub collection without using a specific sub collection's name.

(我很难告诉flutter为每个子集合做一些事情而不使用特定子集合的名称。)

I wanted to pass in a list title to each tile by making a collection reference for each sub collection( list) and calling .id on each one.

(我想通过为每个子collection(list)设置collection引用并在每个sub.call上调用.id来向每个tile传递列表标题。)

Using the collection ID as the title, I'm not yet sure if I can do this or if ill have to make the list title a field inside of each list.

(使用集合ID作为标题,我不确定是否可以执行此操作,或者是否必须使列表标题成为每个列表中的一个字段。)

Either way, I need to find out how to do something for each subcollection inside a particular document.

(无论哪种方式,我都需要找出如何为特定文档中的每个子集合做一些事情。)

.forEach seems to only work on document fields, not subcollections?

(.forEach似乎仅适用于文档字段,而不适用于子集合?)

What am I doing wrong?

(我究竟做错了什么?)

I'm sure there is a better way to go about this.

(我相信有更好的方法可以解决此问题。)

I have not included any code as this is a big picture kind of question.

(我没有包含任何代码,因为这是一个大问题。)

  ask by BlueOverBrown translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

There is no method in the Firestore client-side SDKs to get all collections (or subcollections under a specific document).

(Firestore客户端SDK中没有方法来获取所有集合(或特定文档下的子集合)。)

Such API does exist in the server-side SDKs, but not in the client-side SDKs.

(这样的API 确实存在于服务器端SDK中,但存在于客户端SDK中。)

See:

(看到:)

So you'll need to know the collections already, typically by changing your data model.

(因此,您通常需要通过更改数据模型来了解集合。)

For example by creating a document for each list's metadata, and then storing the list items in a subcollection with a known name under that document.

(例如,通过为每个列表的元数据创建一个文档 ,然后将列表存储在该文档下具有已知名称的子集合中。)

That way you can get all lists by querying for the documents, which is possible within the API.

(这样,您可以通过查询文档来获取所有列表,这在API中是可能的。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...