2017-10-08 63 views
0

我试图用下面的代码更新数据库上的'现金'值。Ionic 3更新Firebae上的数据库

updateCash() { 
    const userId = this.authCtrl.showUser().uid; 
    this.afDatabase.database.ref(`users/${userId}/userInfos`).transaction(eventSnapshot => { 
     eventSnapshot.cash += 100; 
     this.afDatabase.list(`users/${userId}/userInfos`).push(eventSnapshot.cash); 
    }); 
    } 

但是出现了一些问题,并保存这样的结果。

enter image description here

我该如何解决呢?谢谢。

回答

0
updateCash() { 
    const userId = this.authCtrl.showUser().uid; 
    this.afDatabase.database.ref(`users/${userId}/userInfos`).update({ 
     cash:200}).then(res => { 
     console.log(res) 
    }) 
} 
+0

如何更新现金=现金+200没有现金:200? – onurkaya