【发布时间】:2017-03-19 08:09:03
【问题描述】:
如何使用 React 在 Firebase 数据库的顶层设置值。
一个教程(在付费墙后面)解释了在子记录中设置一个值,但我还没有弄清楚如何在顶层进行。
更新子记录:
componentDidMount: function() {
this.ref = new Firebase('<url>');
var childRef = this.ref.child(this.props.params.username);
this.bindAsArray(childRef, 'notes');
},
handleAddNote: function(newNote) {
this.ref.child(this.props.params.username)
.child(this.state.notes.length).set(newNote);
}...
尝试执行以下操作,但不确定如何获取顶层项目的长度。
componentDidMount: function() {
this.ref = new Firebase('<url>');
this.bindAsArray(this.ref, 'notes');
},
handleAddNote: function(newNote) {
this.ref.child(this.state.notes.length).set(newNote);
}...
我几天前开始使用 React,因此我们非常感谢任何建议。
【问题讨论】:
标签: javascript reactjs firebase-realtime-database