我希望有一个搜索栏,用户可以在其中搜索Firebase上的用户,并在键入时更新表视图,而不仅仅是搜索完全匹配。
func searchBar(searchBar: UISearchBar, textDidChange searchText: String) {
if searchBar.text == nil || searchBar.text == "" {
inSearchMode = false
tableView.reloadData()
} else {
inSearchMode = true
let lower = searchBar.text!.lowercaseString
filteredPeopleArray = peopleArray.filter({$0.title.hasPrefix(lower) != nil})
tableView.reloadData()
}
这段代码适用于此,但是对于我来说,这是需要加载的,以便用Firebase中当前的每个用户填充一个数组,并在打开应用程序时不断地在创建新用户时追加他们。
我看到该解析曾经有一个“在键包含字符串的用户中查找”,并且您将在textDidChange中执行查询以解析,但是我看不到Firebase的类似信息。此外,是否不以任何方式加重数据负担,以免每次键入字母时将查询发送到firebase?
例如,Instagram使用哪种方法,例如您输入一些字母并从服务器中返回名称中带有该前缀的用户列表?因此,像“ Bo”可能会返回鲍勃和鲍比的列表。
我无法发表评论,但这是一篇对我有所帮助的文章。
https://www.quora.com/How-would-you-search-a-Firebase-Realtime-Database-with-a-substring
假设您有以下Firebase数据
{
"lambeosaurus": {
"dimensions": {
"height" : 2.1,
"length" : 12.5,
"weight": 5000
}
},
"stegosaurus": {
"dimensions": {
"height" : 4,
"length" : 9,
"weight" : 2500
}
}
}
下面的示例查找名称以字母“ b”开头的所有恐龙。
var ref = new Firebase("https://example.firebaseio.com/");
ref.orderByKey().startAt("b").endAt("b\uf8ff").on("child_added", function(snapshot) {
console.log(snapshot.key());
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句