【问题标题】:Query in firebase在firebase中查询
【发布时间】:2015-01-18 22:57:51
【问题描述】:

需要有关 firebase 查询的帮助。在firebase中如何查询下两层的元素。

{
 Father : {
   Child : {
     Grand-child: {
        "a" : "some  value",
        "email" : "user email id "
      }
}}}

Father 下面有很多 Child 元素

在每个孩子下有很多孙子..我想选择所有有电子邮件以“abc”开头的孙子..怎么做..基本上想选择孙子而不考虑父母对于那个特定元素..感谢任何帮助..

编辑问题:我在文档中找不到该功能..在 Jquery 世界中它可能看起来像这样..

 <div id='top'>
    <div>
        <a href='#'> Second level child 1 </a>
    </div>
    <div>
        <a href='#'> Second level child 2</a>
    </div>
</div>
$( "#top>*>a" ).on('click', function () {
alert("here")
return true;
});

我们在 firebase 中是否有类似的东西,所以获取选择器在 jquery 中所做的事情。感谢您的帮助..

【问题讨论】:

  • 你已经尝试了什么?请编辑您的问题并显示您已经尝试过的代码。
  • 嗨弗兰克..刚刚用jquery示例编辑了这个问题..不确定我们在firebase中是否有类似的东西,它可以帮助我们获取2级(下)元素而忽略中间的内容..
  • 在 Firebase 中,您可以通过 new Firebase('https://your.firebaseio.com/Father/Child/Grand-child').on('value', ... 只获得孙辈。它记录在 (a.o.) firebase.com/docs/web/guide/understanding-data.html
  • 您是否建议遍历每个结果并抛出我不需要的任何一个.. 我需要所有 10 岁的孙子(比如说).. 不管他们的父亲如何 :-).. 我期待像your.firebaseio.com/Father*/Grand-child这样的语法......不确定是否可能......你能详细说明一下吗

标签: firebase


【解决方案1】:

您确实需要遍历所有父亲和孩子。您可以使用 Firebase 的新查询查询子项,但不能使用子项的子项。下面是一个作用于 10 岁孙辈的示例。

var fathersRef = new Firebase('https://your.firebaseio.com');

fathersRef.on('child_added', function(fatherSnap) {
  fatherSnap.ref().on('child_added', function(childSnap) {
    childSnap.ref().orderByChild('age').equalTo(10).on('child_added', function(grandchildSnap) {

      \\ Do something with the grandchild
      var grandChild = grandchildSnap.val();

    });
  });
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 2018-04-12
    • 2020-08-19
    • 2017-06-05
    相关资源
    最近更新 更多