Javascript 使用React在Firebase db的顶层设置一个值
如何使用React在Firebase db的顶层设置值 一个教程(在付费墙后面)解释了如何在子记录中设置一个值,但我还没有弄清楚如何在顶层进行设置 更新子记录:Javascript 使用React在Firebase db的顶层设置一个值,javascript,reactjs,firebase-realtime-database,Javascript,Reactjs,Firebase Realtime Database,如何使用React在Firebase db的顶层设置值 一个教程(在付费墙后面)解释了如何在子记录中设置一个值,但我还没有弄清楚如何在顶层进行设置 更新子记录: componentDidMount: function() { this.ref = new Firebase('<url>'); var childRef = this.ref.child(this.props.params.username); this.bindAsArray(childRef, 'note
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);
},
componentDidMount:function(){
this.ref=新火基(“”);
var childRef=this.ref.child(this.props.params.username);
本.bindAsArray(childRef,'notes');
},
handleAddNote:功能(新注释){
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);
}...
componentDidMount:function(){
this.ref=新火基(“”);
this.bindAsArray(this.ref,“notes”);
},
handleAddNote:功能(新注释){
this.ref.child(this.state.notes.length).set(newNote);
}...
我几天前就开始做出反应,因此非常感谢您的建议。解决方案:
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);
},
以前,由于计算没有元素的特定状态的元素长度,因此每次添加某个元素时,都会覆盖Firebase db中的第一个项目(0索引),因此无法正常工作
这起作用了:
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);
},
componentDidMount:function(){
this.ref=新火基(“”);
this.bindAsArray(this.ref,“notes”);
},
handleAddNote:功能(新注释){
this.ref.child(this.state.notes.length).set(newNote);
},