我使用Firebase作为我的DB,并在前端做出反应。我正在尝试显示用户特定的数据(注释)并显示它。我已经问过相似 问题了,但我认为他们太开放了,所以这更具体:
我已经按照火基非正规化建议组织了我的数据。下面来看看数据是如何构造的:
"notes" : {
"n1" : {
"note" : "[noteData]",
"created_at" : "[date]",
"updated_at" : "[date]",
}
},
"users" : {
"userOne" : {
"name" : "[userName]",
"notes" : {
"n1" : true
}
}
}感谢其他评论者,我已经能够使用ReactFire和泰勒·麦金尼斯来获取每个用户的便笺键列表,并在state中创建一个note对象。这看起来是这样的:
ReactFire
firebaseRef.child('users/' + authData.uid + '/notes').orderByChild('date_updated').on("child_added", function(noteKeySnapshot) {
ref = firebaseRef.child('notes/' + noteKeySnapshot.key());
this.bindAsObject(ref, noteKeySnapshot.key());
}.bind(this)); 再碱基
firebaseRef.child('users/' + authData.uid + '/notes').orderByChild('date_updated').on("child_added", function(noteKeySnapshot) {
base.syncState('notes/' + noteKeySnapshot.key(), {
context: this,
state: noteKeySnapshot.key(),
asArray: false,
});
}.bind(this)); 这两种解决方案都将每个note对象添加到this.state树的顶部。这使得很难作为一个组访问笔记。我想将每个note对象添加到一个数组中,类似于this.state.notes。
如何使用this.state**?**中的ReactFire或Re将每个便笺对象添加到数组中?
对于如何在this.state中访问这些对象,我对其他解决方案持开放态度。
发布于 2016-09-11 14:53:06
如果我没有弄错,你必须把它设置在你放快照的地方。
在吉特卜的例子中,
componentDidMount(){
base.syncState(`notes`, {
context: this,
state: 'notes', //Changes this to whatever you want as inner state.
asArray: true
});
}https://stackoverflow.com/questions/34769689
复制相似问题