我的数据结构如下:
{
"node_1" : {
"node_2": [
{
"id": 1,
"catCode": 1,
"catName": "cat name",
"title": "Title 1",
"description": "description 1"
},
{
"id": 2,
"catCode": 2,
"catName": "cat name",
"title": "Title 2",
"description": "description 2"
},
{
"id": 3,
"catCode": 2,
"catName": "cat name",
"title": "Title 3",
"description": "description 3"
}
]
}
}
title
列表的方式查询?例如:["Title 1","Title 2","Title 3"]
title
列出的"catCode": 2
列表的方式查询?例如:["Title 2","Title 3"]
答案 0 :(得分:0)
Firebase数据库始终返回完整的节点。因此,没有单个读取操作只返回title
下的node_2
个节点。
这意味着也没有只能返回catCode == 2
项目标题的查询。但是你可以获得整个节点,然后用:
DatabaseReference ref = FirebaseDatabase.getInstance().getReference("node_1/node_2");
Query items = ref.orderByChild("catCode").equalTo(2);
items.addValueEventListener(new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot itemSnapshot: dataSnapshot.getChildren()) {
Log.i(TAG, itemSnapshot.child("title").getValue(String.class));
}
}
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, "loadPost:onCancelled", databaseError.toException());
}
};