Firebase查询顺序由名称开始 [英] Firebase Query order by and start at name

查看:117
本文介绍了Firebase查询顺序由名称开始的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在餐厅细节的幻灯片工作,每张幻灯片显示每个餐厅的细节。
我正在做什么来获得餐馆名单。
在初始化的时候,我得到了10个餐馆的名字。
$ b $ p $ firebaseArray(ref.orderByChild('name')。startAt(name) .limitToFirst(限制))



但是,每一个下一个交换,我得到并添加单个餐厅,并删除第一个以防止重载。

问题是,如果有多个相同的名称餐馆,它不能加载另一个交换,它总是得到相同的一个。
我应该做些什么来防止这种情况发生?

保留最后一项显示的,然后将其作为第二个参数到 startAt()

所以:
$ b $ pre $ ref $ orderByChild('name')。 startAt(name,previousLastKey).limitToFirst(limit)

当有多个具有相同值的子元素 name ,查询将从您指定的键开始。因此,采用这种方法,页面1上的最后一个项目成为第2页的锚点项目等。


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?

解决方案

Keep the key of the last item you show, then pass that in as the second parameter to startAt().

So:

ref.orderByChild('name').startAt(name, previousLastKey).limitToFirst(limit)

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查询顺序由名称开始的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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