2017-10-08 62 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