更新时间:2023-12-05 22:49:34
您的引用有误:
myRef = database.getReference("STUDENT").child(child);
在上面的数据快照中将是child
,例如id:ur14cs002
.因此,它当然将永远不存在,因为dataSnapshot将是子代(提供的ID).
In the above the dataSnapshot will be the child
which is this id:ur14cs002
for example. So ofcourse it will never exists, since the dataSnapshot will be the child (which is the id provided).
您需要执行以下操作:-
You need to do this:-
myRef = database.getReference().child("STUDENT");
这样,引用将在节点STUDENT
处,然后orderByChild("id").equalTo(child)
将为您提供正确的结果.这里的dataSnapshot将是(STUDENT)节点.
This way the reference is at node STUDENT
then orderByChild("id").equalTo(child)
will give you the right result. Here the dataSnapshot will be the (STUDENT) node.