跳过FirebaseRecyclerAdapter中的行 [英] Skip Row in FirebaseRecyclerAdapter

查看:109
本文介绍了跳过FirebaseRecyclerAdapter中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 news:{
-KnLRSIOyD7HgldFGty:{
caption:some grounds,
content:some内容,
created_on:1498246403444,
newspaper_id:-KnLPu2N5039ZbqS,
status:false,
thumbnail:thumbnail / 1498254125498
$


$ bnewspaper:{
-KnLRSIOyD7HgldFGty:{
logo:logo / 1498245996906 ,
paper_name:NewsOnline
},
}



我想过滤firebase做这样的事情。
mDatabaseRef.child(news)。orderByChild(newspaper_id)。equalTo(id).orderByChild(status)。equalTo(false);
由于多个orderBy()会在firebase中抛出异常,所以实现这个过滤器的另外一种方式是什么。 解决方案

目前,Firebase只支持每个查询的单个订单。



因此,如果您想要在多个属性(您的案例中为2个查询)上筛选或排序结果,您必须在您的Android代码中进行额外的过滤(或排序)客户端,否则您将不得不提出自己的索引方案,以结合这些属性。



在你的情况下,我建议你添加一个名为 newspaperId_status 的新子,它可以像下面这样获取两个值的连接值:

  newspaperId_status:-KnLPu2N5039ZbqS_false 

通过这种方式你可以查询所有状态为 false



希望有帮助。


"news" : {
    "-KnLRSIOyD7HgldFGty" : {
      "caption" : "some grounds",
      "content" : "some contents",
      "created_on" : 1498246403444,
      "newspaper_id" : "-KnLPu2N5039ZbqS",
      "status" : false,
      "thumbnail" : "thumbnail/1498254125498",
    },
}


"newspapers" : {
    "-KnLRSIOyD7HgldFGty" : {
      "logo" : "logo/1498245996906",
      "paper_name" : "NewsOnline"
      },
}

I want to filter firebase to do something like this. mDatabaseRef.child("news").orderByChild("newspaper_id").equalTo(id).orderByChild("status").equalTo(false); Since multiple orderBy() will throw exception in firebase, what is the other way to achieve the filter.

解决方案

Currently Firebase supports only a single orderBy per query.

So if you want to filter or order the results on more than one property (2 query in your case), you'll either have to do the additional filtering (or ordering) client-side in your Android code or you'll have to come up with your own indexing scheme that combines the properties.

In your case i suggest you add a new child named newspaperId_status which can get the value as concatenation of both values like this:

newspaperId_status: -KnLPu2N5039ZbqS_false

In this way you can query all newspappers which have the status of false.

Hope it helps.

这篇关于跳过FirebaseRecyclerAdapter中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆