如何检索在firebase的所有键 [英] how to retrieve all the keys in firebase android

查看:251
本文介绍了如何检索在firebase的所有键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是一个很好的选择,是我的数据结构





我想检索矩形框中的单个键下的两个键。我有在矩形框中的钥匙。所以如何将这两个键?

解决方案

所有你需要做的是做一个嵌套的查询。首先找到父母的密钥,然后将该密钥传递给下一个查询,然后找到它的子元素。

 列表< user> userList = new ArrayList(); 

mdatabaseRef.addValueEventListener(新ValueEventListener(){
@覆盖
公共无效onDataChange(DataSnapshot dataSnapshot){
为(DataSnapshot孩子:dataSnapshot.getChildren()) {
String key = child.getKey();
fun(key);
}

private void fun(String key){

mdatabaseRef.child(键).addValueEventListener(新ValueEventListener(){
@覆盖
公共无效onDataChange(DataSnapshot dataSnapshot){为(DataSnapshot孩子:dataSnapshot.getChildren()){
User user = postsnapshot.getValue(User.class);
userList.add(user);
}

}
pre>

I want to retrieve all the keys under single key, tried many things, but nothing work till now.

This is my data structure

I want to retrieve two keys which are under single key in rectangle box. I have key which is in rectangle box. so how to these two keys ?

解决方案

All You have to do is do a nested query .! first find key of parent then get pass that key to next query and then find its children.!

List<user> userList=new ArrayList();

         mdatabaseRef.addValueEventListener(new ValueEventListener() {
      @Override     
      public void onDataChange(DataSnapshot dataSnapshot) {
         for (DataSnapshot child: dataSnapshot.getChildren()){
            String key = child.getKey();
             fun(key);
             }

      private void fun(String key){

        mdatabaseRef.child(key).addValueEventListener(new ValueEventListener() {
       @Override     
       public void onDataChange(DataSnapshot dataSnapshot) {for (DataSnapshot child: dataSnapshot.getChildren()){
    User user= postsnapshot.getValue(User.class);
userList.add(user);
     }

        }

这篇关于如何检索在firebase的所有键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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