Firebase,从父母那里获得特殊的认可 [英] Firebase, get specfic chid from parent

查看:32
本文介绍了Firebase,从父母那里获得特殊的认可的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将所有学生节点的子节点中的分支值与我已经拥有的值进行匹配,如果匹配成功,我想在匹配的子节点中检索学生姓名"值,请参见打击图片

I want to match branch value in all child of student nodes with the value I already have and if matched successfully then I want to retrieve 'Student name' value in matched child see blow image

推荐答案

在这种情况下,您正在寻找查询.

You're looking for a query in that case.

要匹配 branch 的值,然后为所有匹配的子节点打印 studentName 的值,请执行以下操作:

To match the value of branch and then print the value of studentName for all matching child nodes, you'd do:

DatabaseReference ref = FirebaseDatabase.getInstance().getReference(".../students");
Query query = ref.orderByChild("branch").equalTo("Electronics Engineering");
query.addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        for (DataSnapshot studentSnapshot: dataSnapshot.getChildren()) {
            Log.d(TAG, studentSnapshot.child("studentName").getValue(String.class));
        }
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
        throw databaseError.toException();
    }
}

这篇关于Firebase,从父母那里获得特殊的认可的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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