From the Firebase API:
Child Added: This event will be triggered once for each initial child at this location, and it will be triggered again every time a new child is added.
Some code:
listRef.on('child_added', function(childSnapshot, prevChildName) { // do something with the child });
But since the function is called once for each child at this location, is there any way to get only the child that was actually added?
Show activity on this post. retrieve childs of Day 1 to an array and count the array that ll be the no of child. Show activity on this post. add another lister to days that will give you all matches you played on a day.
By combining the push() and child() methods, you can create multiple lists of children in the database: mDatabase. child("numbers"). push().
To track things added since some checkpoint without fetching previous records, you can use endAt()
and limit()
to grab the last record:
// retrieve the last record from `ref` ref.endAt().limitToLast(1).on('child_added', function(snapshot) { // all records after the last continue to invoke this function console.log(snapshot.name(), snapshot.val()); });
limit()
method is deprecated. limitToLast()
and limitToFirst()
methods replace it.
// retrieve the last record from `ref` ref.limitToLast(1).on('child_added', function(snapshot) { // all records after the last continue to invoke this function console.log(snapshot.name(), snapshot.val()); // get the last inserted key console.log(snapshot.key()); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With