Firebase - 如何过滤类似于equalTo(),而是检查它是否包含值? [英] Firebase - How can I filter similarly to equalTo() but instead check if it contains the value?

查看:169
本文介绍了Firebase - 如何过滤类似于equalTo(),而是检查它是否包含值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  J-DSKFJASKDFJASKDJ:{
username:Burned
$,
J-KASDJFAKSDJFKDSJ:{
用户名:BurnedFirebase
},
J-DFJKADSJFAKSDJFK:{
用户名:FirbaseFilteringIsVeryLackingThereforItSucks
}

如果我使用这个:

  Query q = database.orderByChild(username)。equalTo(Burned); 

它实际上只返回已烧制 ,尽管数据库中有一个 BurnedFirebase 。这是因为 equalTo()不能像 contains()



是否有类似于 contains()的方法?如果没有,是否有解决方法?

解决方案

如果您的搜索始终位于单词的开头你可以使用一个很高的Unicode字符:

$ p $ query.startAt(Burned) .endAt(Burned \\\)

来自: https://firebase.google.com/docs/database/admin/retrieve-data#range-queries

  ... dinosaursRef.orderByKey()。startAt(b)。endAt(b\ uf8ff)... 




使用的\ uf8ff字符上面的查询是Unicode范围中的非常高的代码点
。因为它在
Unicode中的大部分常规字符之后,查询匹配所有以b开头的值。



Let's say I have this database:

J-DSKFJASKDFJASKDJ:{
   username: "Burned"
},
J-KASDJFAKSDJFKDSJ:{
   username: "BurnedFirebase"
},
J-DFJKADSJFAKSDJFK:{
   username: "FirbaseFilteringIsVeryLackingThereforItSucks"
}

If I use this:

Query q = database.orderByChild("username").equalTo("Burned");

It will actually return only "Burned", although there is a BurnedFirebase in the database. That's because equalTo() doesn't work as a method such as contains().

Is there a method similar to contains()? If not, is there a workaround?

解决方案

If your search is always at the beginning of the word (you're not searching for ned and expecting Burned to come up), you can use a high unicode character:

query.startAt("Burned").endAt("Burned\uf8ff")

From: https://firebase.google.com/docs/database/admin/retrieve-data#range-queries

...dinosaursRef.orderByKey().startAt("b").endAt("b\uf8ff")...

The \uf8ff character used in the query above is a very high code point in the Unicode range. Because it is after most regular characters in Unicode, the query matches all values that start with a b.

这篇关于Firebase - 如何过滤类似于equalTo(),而是检查它是否包含值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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