从没有子文件夹名称的 firebase order value() 检索数据

Retriving data from firebase ordeybyvalue() without child folder name

我可以使用以下代码从 fire-base 检索数据

Firebase ref=mFirebaseRef.child("users");ref.addValueEventListener(new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot snapshot) {
                for (DataSnapshot Snapshot: snapshot.getChildren()) {
                    String tts=Snapshot.getKey();
                    getScore getscore = snapshot.child(tts).child("gamedata").getValue(getScore.class);
                    System.out.println(getscore.getScore());}}

            @Override
            public void onCancelled(FirebaseError firebaseError) {
                System.out.println("The read failed: " + firebaseError.getMessage());
            }
        });

我的文件树是这样的

users  >  213654518999134  > gamedata > highscore=90    
users  >  213654518999142  > gamedata > highscore=176    
users  >  213545189239136  > gamedata > highscore=432    
users  >  213654658999133  > gamedata > highscore=754

"users" 之后的第二个数字是用户 ID。我该如何使用 orderbyvalue 呢?

无法使用 fire-base 教程中提到的以下示例,因为我在中间有一个用户 ID 文件夹

Firebase scoresRef = new Firebase("https://dinosaur-facts.firebaseio.com/scores");
Query queryRef = scoresRef.orderByValue();
queryRef.addChildEventListener(new ChildEventListener() {
@Override
public void onChildAdded(DataSnapshot snapshot, String previousChildKey) {
  System.out.println("The " + snapshot.getKey() + " dinosaur's score is " + snapshot.getValue());
}
// ....    });

您正在寻找 orderByKey():

Firebase users = mFirebaseRef.child("users").orderByKey();
users.addValueEventListener(new ValueEventListener() {

更新:您似乎希望按高分排序,在这种情况下是:

Firebase users = mFirebaseRef.child("users").orderByChild('gamedata/highscore');
users.addValueEventListener(new ValueEventListener() {

看到这个blog post where the feature was introduced. And don't forget to add .indexOn: ['gamedata/highscore'] to the security rules of users