Firebase Query order by 和 start at name [英] Firebase Query order by and start at name
问题描述
我正在制作一个显示餐厅详细信息的幻灯片,每张幻灯片都显示了每家餐厅的详细信息.我正在做什么来获取餐厅名单.初始化时,我按名称获得 10 家餐厅
I working on a slidebox for restaurant details, each slide shows the detail of each restaurant. What I'm doing to get the restaurants list. On initialization, I get 10 restaurants by name
$firebaseArray(ref.orderByChild('name').startAt(name).limitToFirst(limit))
但是每个下一个交换,我最后得到并添加单个餐厅并删除第一个以防止超载.
But one each next swap, I'm getting and adding single restaurant in the end and removing the first one so as to prevent from overloading.
问题是,如果有多个同名餐厅,它无法在交换时加载另一个,它总是得到相同的.我应该做哪些改变来防止这种情况发生?
The issue is, if there are multiple same name restaurants, it's unable to load another one on swap, it always get the same one. What changes should I do to prevent this?
推荐答案
保留您显示的最后一项的 key,然后将其作为第二个参数传递给 startAt()代码>.
Keep the key of the last item you show, then pass that in as the second parameter to startAt()
.
所以:
ref.orderByChild('name').startAt(name, previousLastKey).limitToFirst(limit)
当有多个子项具有相同的 name
值时,查询将从具有您指定的键的子项开始.因此,通过这种方法,第 1 页上的最后一项将成为第 2 页的锚"项,以此类推.
When there are multiple children with the same value for name
, the query will start at the one with the key you specified. So with this approach the last item on page 1 becomes your "anchor" item for page 2, etc.
这篇关于Firebase Query order by 和 start at name的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!