【问题标题】:How to call the Firestore's Grandchild (Document/Child/Grandchild) data?如何调用 Firestore 的孙子(文档/子/孙)数据?
【发布时间】:2019-07-24 14:08:31
【问题描述】:

我想在 Flutter 中调用 Firestore 文档的孙子上下文中的数据。 我只知道如何从儿童上下文中调用数据。

我无法发布图片,所以...我只是解释一下 我的 Firestore 看起来像这样

collection        document       context

Example1 >        e1 >          
                                 class:"A1"

                              v  who
                                 v  0
                                    name:"Jack"
                                    sex:"boy"
                                 v  1
                                    name:"Mike"
                                    sex:"boy"

我已经知道如何使用下面的代码调用“类”,但问题是如何在“谁”下调用“姓名”和“性别”。

    body: StreamBuilder(
     stream: Firestore.instance.collection('Example1').snapshots(),
     builder: (context, snapshot) {
       if (!snapshot.hasData) return const Text('Loading...');
         return ListView.builder(
           itemCount: snapshot.data.documents.length,
           itemBuilder: (context, index) =>
           _buildListItem(context, snapshot.data.documents[index]),
            );
     }),

感谢您回答我的问题

【问题讨论】:

    标签: firebase flutter google-cloud-firestore


    【解决方案1】:
    body: StreamBuilder(
         stream: Firestore.instance.collection('Example1/e1/who').snapshots(),
         builder: (context, snapshot) {
           if (!snapshot.hasData) return const Text('Loading...');
             return ListView.builder(
               itemCount: snapshot.data.documents.length,
               itemBuilder: (context, index) =>
               _buildListItem(context, snapshot.data.documents[index]),
                );
         }),
    

    可以使用集合参数中的路径

    【讨论】:

    • 你得到了什么
    • 没什么!没有数据
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-09
    • 2014-10-08
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多