简体   繁体   English

大孩子的儿童手表上的Firebase

[英]Firebase on child_added watch for the grand children

foo:{
    'uid1':{
        'push1':'bar1'
        'push1':'bar1'
        'push1':'bar1' // watch for child added here
    },
    'uid2':{
        'push1':'bar1'
        'push1':'bar1'
        'push1':'bar1' // watch for child added here
    },
}

Given the schema above, how do I get new child_added under the uid1 or uid2 while watching for foo ? 鉴于上面的架构,如何获取新child_addeduid1uid2 ,同时观察foo

dbRef.child('foo')
    .on('child_added', snap => {
        console.log(snap.key);
        console.log(snap.val());
    });

I have this query above, but it only fires when the new data is added directly under foo but not when the data is added to foo 's children. 我有这个上面的查询,但是当新数据添加直属它只激发foo而不是当数据被添加到foo的孩子。

Thanks. 谢谢。

You'd have to wire up another listener for the children: 您必须为孩子们连接另一个听众:

dbRef.child('foo')
    .on('child_added', snap => {
        console.log(snap.key);
        console.log(snap.val());
        dbRef.child('foo').child(snap.key)
            .on('child_added', snap => {
                console.log(snap.key);
                console.log(snap.val());
            });
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM