首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用ReactFire或Firebase从Firebase显示用户特定的数据

使用ReactFire或Firebase从Firebase显示用户特定的数据
EN

Stack Overflow用户
提问于 2016-01-13 14:50:24
回答 1查看 405关注 0票数 0

我使用Firebase作为我的DB,并在前端做出反应。我正在尝试显示用户特定的数据(注释)并显示它。我已经问过相似 问题了,但我认为他们太开放了,所以这更具体:

我已经按照火基非正规化建议组织了我的数据。下面来看看数据是如何构造的:

代码语言:javascript
复制
"notes" : {
    "n1" : {
        "note" : "[noteData]",
        "created_at" : "[date]",
        "updated_at" : "[date]",
    }
},
"users" : {
    "userOne" : {
        "name" : "[userName]",
        "notes" : {
            "n1" : true
        }
    }
}

感谢其他评论者,我已经能够使用ReactFire泰勒·麦金尼斯来获取每个用户的便笺键列表,并在state中创建一个note对象。这看起来是这样的:

ReactFire

代码语言:javascript
复制
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)); 

再碱基

代码语言:javascript
复制
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中访问这些对象,我对其他解决方案持开放态度。

EN

回答 1

Stack Overflow用户

发布于 2016-09-11 14:53:06

如果我没有弄错,你必须把它设置在你放快照的地方。

在吉特卜的例子中,

代码语言:javascript
复制
componentDidMount(){
  base.syncState(`notes`, {
    context: this,
    state: 'notes', //Changes this to whatever you want as inner state.
    asArray: true
  });
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34769689

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档