我使用Firebase for Android,发现orderByChild("key")
方法似乎不适用于数组;我尝试检索按award_year
值排序的所有year
条目。
这就是我提出的:
mDatabase.child("awards").orderByChild("createdAt").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
final AwardType awardType = new AwardType();
final ArrayList<Award> awards = dataSnapshot.getValue(awardType);
}
});
非常感谢您的帮助。
我已添加规则:
我的结构如下:
{ "awards": [
{
"award_body": "2009 QR Master Design Awards",
"award_received": "Finalist for Bathrooms $30,000, Qualified Remodeler Magazine",
"createdAt": "2015-11-20T03:43:58.009Z",
"logo": {
"__type": "File",
"name": "tfss-b2a0130d-d9ac-46e6-a29f-c9d9db666909-qualirem1.png",
"url": "awards/thumbnails/tfss-b2a0130d-d9ac-46e6-a29f-c9d9db666909-qualirem1.png"
},
"objectId": "0cE0zA7ciS",
"updatedAt": "2015-11-20T03:46:57.472Z",
"year": {
"__type": "Pointer",
"className": "award_years",
"objectId": "Zp3oDtzpTY"
}
},
{
"award_body": "2014 NAHB",
"award_received": "Best of American Living Awards (BALA) Platinum Award Winner, Kitchen Remodel $100,001 \u0026 over",
"createdAt": "2015-11-20T05:36:55.359Z",
"logo": {
"__type": "File",
"name": "tfss-3cce2507-18fe-4aac-b039-54c343f27473-nahb.png",
"url": "awards/thumbnails/tfss-3cce2507-18fe-4aac-b039-54c343f27473-nahb.png"
},
"objectId": "1ckh7kjxfN",
"updatedAt": "2015-11-20T05:45:02.307Z",
"year": {
"__type": "Pointer",
"className": "award_years",
"objectId": "aL7crUC7Qc"
}
}]
}