Total number of records in Firebase (when am I done counting?)

前端 未结 3 1484
小蘑菇
小蘑菇 2020-12-19 16:33

Counting records in a table is obviously a manual effort until you guys get some of that spiffy new functionality already in the works ;)

However, I\'m stuck on even

3条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-19 17:18

    With "child_added" there is no way to know when you've received the "last" item. If you're looking to count all of the children that existed at a particular point in time, I'd suggest using the "value" event as follows:

    var table = new Firebase('http://beta.firebase.com/user/tablename');
    
    table.on('value', function(snapshot) {
       var count = 0;
       snapshot.forEach(function() {
           count++;
       });
       //count is now safe to use.
    });
    

提交回复
热议问题