有没有办法用 firebase 监视 grandchild_added 事件?
我已经使用node.js javascript 库为child_added 设置了一个观察者,但是当添加子项的子项时它不会触发。
我正在设置会员状态信息,并想知道用户何时进入房间。
i.e.
成员/房间/uname
很多情况下使用child_changed会非常麻烦。这是监听子事件本身的更好方法。
为根注册一个侦听器,并为每个子级注册一个侦听器。
下面是 javascript 代码来演示这一点:
var Firebase = require("firebase");
var firebaseParentUrl = config.firebase.url
var firebaseChildUrl = config.firebase.url + "/child"
var parent = new Firebase(firebaseParentUrl, config.firebase.secret);
theParent.on("child_added", function (snapshot) {
var id = snapshot.key()
var theChild = new Firebase(firebaseChildUrl + id, config.firebase.secret)
theChild.on("child_added", function (snapshot) {
var grandChild = snapshot.val()
//now do something with grandChild
})
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)