具有部分匹配值的Firebase iOS查询数据 [英] Firebase iOS query data with partially matching value
问题描述
Firebase queryEqualToValue
将项 EQUAL 返回指定的键或值.我们如何查询 PARTIALLY MATCH 到指定键或值的项目?
Firebase queryEqualToValue
returns items EQUAL to the specified key or value. How can we query for items PARTIALLY MATCH to the specified key or value?
推荐答案
我们可以结合使用startAt()和endAt()来限制查询的两端. 以下示例查找名称以 字母"b":
We can combine startAt() and endAt() to limit both ends of our query. The following example finds all dinosaurs whose name starts with the letter "b":
let ref = Firebase(url:"https://dinosaur-facts.firebaseio.com/dinosaurs")
ref.queryOrderedByKey().queryStartingAtValue("b").queryEndingAtValue("b\u{f8ff}")
.observeEventType(.ChildAdded, withBlock: { snapshot in
println(snapshot.key)
})
上面的查询中使用的f8ff字符是一个很高的代码点 在Unicode范围内.因为它是在大多数常规字符之后 Unicode,查询匹配所有以b开头的值.
The f8ff 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 iOS查询数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!