Is there a way to know in what context Child Added is called? Particularly page load vs. other events

后端 未结 3 1209
故里飘歌
故里飘歌 2021-01-21 12:57

Here\'s my scenario. When child is added via a browser event post page load, I want to indicate it in the title. But on page load, child added is called as well.

How can

3条回答
  •  难免孤独
    2021-01-21 13:30

    I thought I would update Kato's answer as Datasnapshot.name() and limit have now both been depreciated.

    I decided to make it a bit more simple as well ;)

      // connect to firebase
      var fb = new Firebase("https://your-firebase-ref/");
      var firstTime = false;
    
      fb.limitToLast(1).on('child_added', function(snapshot) {
        if (firstTime) {
          console.log(snapshot.key(), snapshot.val());
        };
        firstTime = true;
      });

    I hope this helps

提交回复
热议问题