[英]Firebase sub-child removed
Is there any way to get if subchild removed. 如果删除了子孩子,有什么办法吗? db structure is:
db结构为:
users:{
a: {
friends: {
b:Jhon,
c:Ted
},
b: {
friends: {
a: Tom
}
},
c: {
friends:{
a: Tom
}
}
}
I want get event while anybody removes any child from friends. 我想得到事件,而任何人都从朋友中删除任何孩子。 Attaching event to every user is not a good way.
将事件附加到每个用户不是一个好方法。
I am trying in node.js admin 我正在尝试在node.js管理员中
Here is another way, you can create a special node for "friend removal request", so the client only writes to this node, then the server handles the deletion. 这是另一种方法,您可以为“删除朋友的请求”创建一个特殊的节点,因此客户端仅写入该节点,然后服务器处理删除。
First, look at this database structure 首先,看一下这个数据库结构
{
users: {
a: {
friends: {
b:Jhon,
c:Ted
},
}
b: {
friends: {
a: Tom
}
},
c: {
friends:{
a: Tom
}
}
}
friend_removal_request : {
<push_id>: {
first_user: a,
second_user: b
}
}
}
child_added
listener to friend_removal_request
child_added
侦听器附加到friend_removal_request
DatabaseReference.push()
method) to friend_removal_request
. DatabaseReference.push()
方法)将新条目写入friend_removal_request
。 first_user
is the user's id, second_user
is their friend's id first_user
是用户的ID, second_user
是他们的朋友的ID null
value (or call remove()
) to /users/$first_user/friends/$second_user
and /users/$second_user_user/friends/$first_user
null
值(或调用remove()
)设置为/users/$first_user/friends/$second_user
和/users/$second_user_user/friends/$first_user
来删除其友谊/users/$second_user_user/friends/$first_user
snapshot.ref.remove()
snapshot.ref.remove()
Now, the listener is only attached to a node. 现在,侦听器仅附加到一个节点。
This is my idea, let me know if you have another concern with this method. 这是我的主意,如果您对此方法还有其他疑问,请告诉我。 Hope this helps :)
希望这可以帮助 :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.