Firebase查询顺序由名称开始 [英] Firebase Query order by and start at name
问题描述
我正在做什么来获得餐馆名单。
在初始化的时候,我得到了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屋!