Firebase更新数据,但几秒钟后将其更改回原始的“ angularFire”

问题描述 投票:0回答:1

我正在尝试使用angular和angularFire更新Firebase实时数据库上的数据,数据发生变化,但几秒钟后又恢复为原始数据,这是我正在使用的功能。

onSaveDateUpdate(){
    let temp = {
      period:{
        startDate:'',
        endDate:'',
        periodType:''
      },
      updatedTime:("0" +(this.r.getMonth()+1)).slice(-2)+"/"+("0" +this.r.getDate()).slice(-2)+"/"+this.r.getFullYear()+" "+this.r.getHours()+":"+this.r.getMinutes()+":"+this.r.getSeconds()
    };
    var save =this.onEndDateValidator();
    if(save){
      temp.period.startDate = this.datePipe.transform(this.editStartDate,'MM/dd/yyyy');
      temp.period.endDate = this.datePipe.transform(this.editEndDate,'MM/dd/yyyy');
      temp.period.periodType = this.periodType;
      const itemRef = this.db.object(URL );
      this.showDateEdit = !this.showDateEdit;
      itemRef.update(temp).then(() => {
        ... 
      });
    }
javascript angular firebase firebase-realtime-database angularfire
1个回答
1
投票

此行为通常意味着您具有拒绝写操作的安全规则。

[当您在应用中执行写入操作时,Firebase客户端最初会假定写入将成功,并立即触发本地事件。这是使用Firebase时UI更新如此之快的原因之一。

在服务器上,数据库根据您的安全规则检查写操作。如果用户被授权,则允许写入,否则拒绝写入。在这两种情况下,服务器都会将结果通知客户端。并且在拒绝写入的情况下,客户端将确保更新本地状态以反映服务器状态。还原本地状态听起来像您所看到的,并且延迟是有意义的(如果是由于客户端与服务器之间的距离/延迟引起的)。

© www.soinside.com 2019 - 2024. All rights reserved.