我尝试使用Firebase加入三个数据。我想检索school name
查询classes
数据只知道保护密钥g1
。我知道它可以在两个单独的调用中完成,但我只是在一次调用服务器时尝试这样做。
有可能吗?
学校
schools :
schoolKey1 :
name: School One
schoolKey2 :
name: School Two
类
classes :
someKey1 :
name: Class One
school : schoolKey1
guard : g1
保护
guards :
g1 :
name: Pipoy Pat
答案 0 :(得分: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
}
});
}
});