2015-07-28 31 views
1

我尝试使用Firebase加入三个数据。我想检索school name查询到classes只知道防护密钥的数据是g1。我知道它可以在两个不同的调用中完成,但我只是在一次调用服务器的过程中尝试完成。Firebase在Android中加入数据

有点可能吗?

学校

schools : 
    schoolKey1 : 
    name: School One 
    schoolKey2 : 
    name: School Two 

classes : 
    someKey1 : 
    name: Class One 
    school : schoolKey1 
    guard : g1 

卫队

guards : 
    g1 : 
    name: Pipoy Pat 

回答

3

这可能是太晚了,但你会需要遵循文档here

类似:

var ref = new Firebase("https://myApp.firebaseio.com/"); 

    // fetch classes 
    ref.child("classes").addChildEventListener(new ChildEventListener() { 
     @Override 
     public void onChildAdded(DataSnapshot snapshot, String previousChildKey) { 
     //get school key 
     String schoolKey = snapshot.getKey(); 

     //get school name from key 
     ref.child("schools/" + schoolKey + "/name").addListenerForSingleValueEvent(new ValueEventListener() { 
      @Override 
      public void onDataChange(DataSnapshot snapshot) { 
      System.out.println("The school name is " + snapshot.getValue()); 
      } 

      @Override 
      public void onCancelled(FirebaseError firebaseError) { 
      // ignore for now 
      } 
     }); 
     } 
    }); 
+0

这工作,但它不是实时的 - 没有检测到变化。你知道更好的解决方案吗? –

+0

帮助我很多谢谢 –