【发布时间】:2017-12-09 06:45:44
【问题描述】:
问题
使用由 React Native 创建的社交媒体应用程序,我尝试使用快照功能从我的 firebase 服务器获取数据,然后将该值加 1,然后在服务器上更新该值。我这样做的代码是:
this.setState({
comments: firebase.database().ref('posts/'+this.state.passKey).once('value', function(snapshot) {snapshot.val().comments})
})
firebase.database().ref('posts').child(this.state.passKey).update({
comments: this.state.comments+1
})
当我运行这段代码时,我得到一个错误,说:
Reference.update failed:
First argument contains NaN in property 'posts.randompostkey.comments'
我的服务器
【问题讨论】:
标签: javascript firebase react-native firebase-realtime-database