我最终的计划是创建一个手风琴列表,通过单击相应的类别显示食物名称。但是,现在我不需要显示重复的类别,例如" Dairy"。我怎么能这样做?
我在Firebase中有以下数据库结构:
{
"aePQkvozV6gehP7ihjN0OWCltKu2" : {
"-Kv4xipPl0_2oztTMhaS" : {
"category" : "Dairy",
"foodname" : "Milk",
"state" : "on"
},
"-Kv4xipRPvW5ejLTtosX" : {
"category" : "Dairy",
"foodname" : "Butter",
"state" : "on"
},
"-Kv4xipS3lNBqYzknNhL" : {
"category" : "Meat",
"foodname" : "Chicken",
"state" : "on"
},
"-Kv4xipTchrGh8D_lGmR" : {
"category" : "Produce",
"foodname" : "Strawberries",
"state" : "on"
}
}
}
我有以下查询:
getUserList(user): FirebaseListObservable<any> {
console.log('firebase.auth().currentUser', user);
return this.db.list('userlist' + '/' + user.uid, {
query: {
orderByChild:'category'
}
});
}
以下HTML显示类别:
<ion-item id="foodnames" *ngFor="let list of lists" (click)="additem(item)">
{{list.category}}
</ion-item>
答案 0 :(得分:0)
在这种情况下,我猜你应该编辑你的数据库结构 喜欢
{
"Dairy":
{
"aePQkvozV6gehP7ihjN0OWCltKu2" : {
"-Kv4xipPl0_2oztTMhaS" : {
"foodname" : "Milk",
"state" : "on"
},
"-Kv4xipRPvW5ejLTtosX" : {
"foodname" : "Butter",
"state" : "on"
}}
"Meat":{
"-Kv4xipS3lNBqYzknNhL" : {
"foodname" : "Chicken",
"state" : "on"
}}
}
现在您只能获取特定类别