尝试安排group2
个成员,因此在这种情况下结果应为user2
,并且不会显示它是否存在:
{
"users":{
"user1":{
"username":"john",
"groups":{
"group1":true,
"group3":true
}
},
"user2": ...,
}
"groups": {
"group1"{
...
},
"group2"{
"group_name":"Moderators",
"members":{
"user2":true
}
}
}
}
我试过了:
const ref = firebase.database().ref('groups');
ref.orderByChild("user2").on("child_added", function (snapshot) {
console.log(snapshot.key)
});
但没有运气
答案 0 :(得分:1)
如果您要列出第2组的成员:
const ref = firebase.database().ref('groups');
ref.child("group2/members").on("child_added", function (snapshot) {
console.log(snapshot.key)
});
这将打印:
用户2