【问题标题】:Firebase query references/collectionsFirebase 查询参考/集合
【发布时间】:2016-10-20 04:48:34
【问题描述】:

我是使用 Firebase 和 NoSQL 的新手,我将它与 AngularJS 一起使用,并且在查询引用/“连接”时遇到问题,我相信我已经按照推荐的方式构建了表格。我有一个 Players 表和一个 Groups 表,下面有几个示例对象 -

球员表 -

P1 : {Name: 'Tobias', Age: 24, Groups: {GroupA: true}, Scores: {S1: true}}

P2 : {Name: 'Josh', Age: 22, Groups: {GroupA: true}, Scores: {S2: true}}

组表 -

GroupA : {Name: 'Group A', Players: {P1: true, P2: true}}

分数表 -

 S1 : {Score: 5, PlayerId: P1}

 S2 : {Score: 3, PlayerId: P2}

现在我想要获取 GroupA 中的所有玩家,我执行以下操作。

Players
    .orderByChild('Groups/GroupA')
    .equalTo(true)
    .on('value', function(snapshot){
        $scope.myPlayers = snapshot.val();
    })

我现在有我的 P1 和 P2 玩家对象,但我也想获得他们的相关分数作为他们对象的一部分,这就是我卡住的地方。有没有一种简单的方法可以做到这一点?如果有人能解释下一步,那就太好了。

【问题讨论】:

    标签: javascript firebase firebase-realtime-database nosql


    【解决方案1】:

    要加入数据,您可能需要使用 firebase-util 库。您甚至可以在应用程序中实现之前创建自己的数据进行测试。您只需点击此链接: http://firebase.github.io/firebase-util/#/toolbox/NormalizedCollection/

    希望对您有所帮助!让我知道事情是否按预期工作:)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-26
      • 1970-01-01
      • 1970-01-01
      • 2019-03-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多