2017-03-18 2 views
0

React를 사용하여 Firebase db의 최상위 레벨에 값을 설정하는 방법은 무엇입니까?React를 사용하여 Firebase db의 최상위 레벨에 값을 설정하십시오.

자습서 (유료화 배경)에서는 하위 레코드의 값 설정에 대해 설명하지만 최상위 레벨에서 수행하는 방법을 찾지 못했습니다.

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); 
}... 

저는 몇 일 전에 반응을 시작 했으므로 조언을 주시면 감사하겠습니다.

답변

0

솔루션 : 그것은 이전으로 인해 각각의 시간 뭔가 DB를 중포 기지의 첫 번째 항목 (0 인덱스)를 덮어, 어떤 요소가 없었 특정 상태에 대한 요소의 길이를 계산에 작동하지 않는

가 추가되었습니다.

이 일 :

componentDidMount: function() { 
    this.ref = new Firebase('<url>'); 
    this.bindAsArray(this.ref, 'notes'); 
}, 
handleAddNote: function(newNote) { 
    this.ref.child(this.state.notes.length).set(newNote); 
}, 
관련 문제