从 firebase 的另一个列表中获取数据的最佳方法是什么
whats the best way too get data from another list from firebase
我有这个数据库:
循环所有球队并获取球员姓名的最佳方式是什么?
例如 html:
团队:超级巨星
球员:亚历克斯、大卫
我很难循环 firebase observable
重构您的数据,使其更加扁平。为了支持玩家在多个团队中,您可以创建一个引用 Players
和 Teams
.
的节点
{
Players: {
-Ksegwegwegwg: {
name: "alex"
},
-K43yhwhyehwh: {
name: "david"
}
},
Team: {
-Knwgjkwn4333: {
name: "superstars"
}
},
InTeam: {
-Kwegbwegwwegw: {
player: "alex",
team: "superstars"
},
-Kwegbwegwwegw: {
player: "david",
team: "superstars"
}
}
}
只要玩家加入团队,您就可以添加到 InTeam
。
那么你可以这样查询:
const queryObservable = db.list('/InTeam', {
query: {
orderByChild: 'team',
equalTo: 'superstars'
}
});
// Result = [{player: "alex", team: "superstars"}, {player: "david", team: "superstars"}];
我有这个数据库:
循环所有球队并获取球员姓名的最佳方式是什么?
例如 html:
团队:超级巨星 球员:亚历克斯、大卫
我很难循环 firebase observable
重构您的数据,使其更加扁平。为了支持玩家在多个团队中,您可以创建一个引用 Players
和 Teams
.
{
Players: {
-Ksegwegwegwg: {
name: "alex"
},
-K43yhwhyehwh: {
name: "david"
}
},
Team: {
-Knwgjkwn4333: {
name: "superstars"
}
},
InTeam: {
-Kwegbwegwwegw: {
player: "alex",
team: "superstars"
},
-Kwegbwegwwegw: {
player: "david",
team: "superstars"
}
}
}
只要玩家加入团队,您就可以添加到 InTeam
。
那么你可以这样查询:
const queryObservable = db.list('/InTeam', {
query: {
orderByChild: 'team',
equalTo: 'superstars'
}
});
// Result = [{player: "alex", team: "superstars"}, {player: "david", team: "superstars"}];