Firebase.ServerValue.TIMESTAMP not synched between listeners and the client that actually adds data

前端 未结 2 955
面向向阳花
面向向阳花 2020-12-21 06:18

Here is the simplest example possible:

var fb = new Firebase(\'https://xxxxxxxxxxx.firebaseio.com/test\');

fb.limitToLast(1).on(\'child_added\', function(sn         


        
2条回答
  •  南笙
    南笙 (楼主)
    2020-12-21 07:03

    For the Realtime SDK this is the expected behavior. Eventually, the timestamp will reflect the proper server value. But, if this does not suit your needs you can use the REST API.

    function addTimestamp() {
      fetch('https://.firebaseio.com/test/.json', {
        method: 'post',
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({
          '.sv': 'timestamp' // add a timestamp
        })
      });
    }
    

    This will not use the local timestamp, and in combination with the Realtime SDK, each client will have the same timestamp on the first update.

提交回复
热议问题