[英]How do I retrieve all the vases from my Firebase Database?
I would simply like to retrieve all the data from my Products node I am unsure how to do this, this is how my database is set up. 我只是想从我的“产品”节点检索所有数据,我不确定该怎么做,这就是我的数据库的设置方式。
Producuts(yes I am aware products is misspelled)
sH8LzoaH9UaXahlmssixTpvQy8q2 (UUID)
-LiToCix_BpBU2G5b0GF (Push value)
Description:
PostImage:
-Lj71JBxtvmbjTRLaA-6 (Push value)
Description:
PostImage:
-Lj71K5QfoguoLKdUDL4. (Push value)
Description:
PostImage:
As you can see from my code snippet I have already set a value event listener, I am unsure of how to retrieve all the values from the Products node. 从代码片段中可以看到,我已经设置了一个值事件侦听器,但不确定如何从“产品”节点中检索所有值。
public void fetchUserInfo(){
productDatabaseRefrence = FirebaseDatabase.getInstance().getReference().child("Producuts").child(currentUser.getUid());
productDatabaseRefrence.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String mGroupId = productDatabaseRefrence.push().getKey();
Log.i("id",mGroupId);
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
According to the image, you have the following database: 根据图片,您具有以下数据库:
Producuts(yes I am aware products is misspelled)
sH8LzoaH9UaXahlmssixTpvQy8q2 (UUID)
-LiToCix_BpBU2G5b0GF (Push value)
Description:
PostImage:
-Lj71JBxtvmbjTRLaA-6 (Push value)
Description:
PostImage:
-Lj71K5QfoguoLKdUDL4. (Push value)
Description:
PostImage:
To retrieve the description
and postimage
in your database, try the following: 要检索数据库中的description
和postimage
,请尝试以下操作:
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for(DataSnapshot ds : dataSnapshot.getChildren()){
String key = ds.getKey();
String desc = ds.child("Description").getValue(String.class);
String img = ds.child("PostImage").getValue(String.class);
}
}
Using getKey()
you can retrieve the random id example -LiToCix_BpBU2G5b0GF (Push value)
and using child()
you can retrieve the different children under each random id. 使用getKey()
可以检索随机ID示例-LiToCix_BpBU2G5b0GF (Push value)
,使用child()
可以检索每个随机ID下的不同子项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.