取消链接父级监听器是否适用于Firebase中的孩子 [英] Unlink listener for parent does it applied to children in Firebase
问题描述
myRef.off();
但是我发现有些听众仍然附着在上面。
我的问题是:当你把监听器关闭一个父节点,它传播给孩子,或者我应该把每个级别分开吗?
$ $ $ $ $ $ $ $ $ ref()value,function(snapshot){
console.log(parent:+ JSON.stringify(snapshot.val()));
}); $($)$ b $ ref.child(child)。(value,function(snapshot){
console.log(child:+ JSON.stringify(snapshot.val()));
});
ref.set('1');
ref.child('child')。set('2');
ref.off();
ref.child('child')。set('3');
ref.child('child')。off();
ref.set('4');
输出:
父母:1
孩子:2
父母:{孩子:2}
孩子:3
所以在父监听器上调用 off
之后,子监听器仍然会触发( 3
)。但是,如果我们得到同样的孩子,并调用 off
,它就不会再有了(4
)。 / p>
JSBin: http://jsbin.com / wutaza / edit?js,console
$ b 结论:off()不会从子节点中删除侦听器。
I am using firebase to synch data in a real time app. After some treatment, I want to unlink all listeners added. So I put
myRef.off();
But I discover that some listeners are still attached.
My question is: when you put listeners to off for a parent node does it propagate to children or should I put off each level separately?
Let's try it.
ref.on("value", function(snapshot) {
console.log("parent: "+JSON.stringify(snapshot.val()));
});
ref.child("child").on("value", function(snapshot) {
console.log("child: "+JSON.stringify(snapshot.val()));
});
ref.set('1');
ref.child('child').set('2');
ref.off();
ref.child('child').set('3');
ref.child('child').off();
ref.set('4');
The output:
parent: "1"
child: "2"
parent: {"child":"2"}
child: "3"
So after calling off
on the parent listener, the child listener still fires ("3"
). But if we get the same child and call off
, it doesn't for anymore ("4"
).
JSBin: http://jsbin.com/wutaza/edit?js,console
Conclusion: off() doesn't remove listeners from child nodes.
这篇关于取消链接父级监听器是否适用于Firebase中的孩子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!