从Firebase中的嵌套节点获取数据 [英] Fetch data from nested nodes in Firebase

查看:66
本文介绍了从Firebase中的嵌套节点获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Firebase 在android中构建我的第一个项目.

I am building my first project in android using Firebase.

我已经构建了一个 Firebase's database ,其主节点为 post media 作为其子节点,media节点可以包含多个特定帖子的值,也可以在其中包含一个值.

I have build a Firebase's database which is having main node as post, media as its child node, media node can contain multiple values for a particular post or can have one value inside it.

所以我想获取具有特定发布节点的媒体子节点值.

So i want to fetch media child node values with particular post node.

能请你帮我吗?

任何帮助将深表感谢.

Any help will deeply appreciated.

请查看下面的屏幕截图.

Please check the screenshots below.

推荐答案

首先,您需要阅读文档了解如何从Firebase检索数据.

First you need to read docs to know how to retrieve data from firebase.

您的数据将像这样...

and your data will be like this ...

final Firebase ref = new Firebase("URL/posts");
    ref.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot userSnapshot : dataSnapshot.getChildren()) {
//u can handle your variables name in GetData class
                GetData posts = userSnapshot.getValue(GetData.class);

以另一种方式..

                DatabaseReference  databaseReference = FirebaseDatabase.getInstance().getReference().child("posts");
                String user_id = firebaseAuth.getCurrentUser().getUid();
               databaseReference.child(user_id).child("media").getValue("user_id").getValue(etc);

您可以将最后一行另存为String,以便在任何地方重复使用.

You might save last line as String to reuse it anywhere.

更新:

要获取数据,必须使用Firebase 示例

And to Fitch data You have to use Firebase adapter, example

这篇关于从Firebase中的嵌套节点获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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