将侦听器添加到Firebase生成的密钥中的一个孩子? [英] Add a listener to a child inside of a firebase generated key?
问题描述
+ activity
+ -K5p_pBXog4kb0SVLXxj
text:'something',
当:111
+线程
+ -K5paF53zm3cuudP9FUQ
id:8,
text:'别的东西'
有没有办法将一个监听器添加到像/ activity / * / thread这样的活动中的任何新的线程中?
添加新活动时,我得到这些饲料,但是当一个线程被追加没有什么触发器。我需要将[thread]部分移出到它自己的根目录,并将线程ID与活动ID进行匹配,以便知道何时对主活动线程进行线程评论?
根据您的评论更新答案。
您要收听 / activity / $ theid / thread / $ threadId
:
不是嵌套,而是分解 现在,当添加一个新线程时,您可以只听$ / thread / $ threadId $ c
:
$ {
threadActivity:{
$ activity $ b $ $ $ threadId $ {
$ b}
code $
var ref = new Firebase('https://< my> .firebaseio.com / threadActivity');
var activityRef = ref.child('some-id');
activityRef.on('child_added',function(snap){
//将会更新你所在位置的每个孩子,并且每个孩子都被添加
console.log(snap.val()) ;
});
Given the layout
+ activity
+ -K5p_pBXog4kb0SVLXxj
text:'something',
when:111
+ thread
+ -K5paF53zm3cuudP9FUQ
id:8,
text:'something else'
Is there a way to add a listener to any new "thread" inserts inside of activity like /activity/*/thread?
When new activities get added I am getting the feed on those but when a thread is appended nothing triggers. Do I need to move the [thread] section out to it's own root and match thread ID's with activity ID's to know when a thread comment is made against the main activity thread?
Updating the answer based upon your comment.
You want to listen to /activity/$theid/thread/$threadId
:
Rather than nesting, break out the /thread/$threadId
into it's own location at the root.
{
"threadActivity": {
"$activityId": {
"$threadId" : {
}
}
}
}
Now when a new thread is added you can just listen to /threadActivity/$activityId
:
var ref = new Firebase('https://<my>.firebaseio.com/threadActivity');
var activityRef = ref.child('some-id');
activityRef.on('child_added', function(snap) {
// will update you for every child at the location and each child added
console.log(snap.val());
});
这篇关于将侦听器添加到Firebase生成的密钥中的一个孩子?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!