Firestore 分页 - 是否有与 firebase 的 limitToLast 兼容的查询? [英] Firestore pagination - Is there any query compatible with firebase's limitToLast?

查看:17
本文介绍了Firestore 分页 - 是否有与 firebase 的 limitToLast 兼容的查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法用firestore实现反向分页?我正在努力使用 firestore 实现分页,并且对它的 firestore 查询有限.前向分页可以通过startAtlimit 方法进行,没问题.但是反向分页不容易做到,因为我们只有 endBeforeendAt 方法,我们如何从给定的文件?我知道实时数据库有方法 limitToLast.Firestore 有这样的查询吗?(此外,我需要实现多重排序,因此无法使用ASC"或DESC"排序获取最后一个文档)非常感谢帮助.

Is there a way to implement back pagination with firestore? I am struggling to implement pagination with firestore, and there are limited firestore queries for it. Forward pagination can be made by startAt and limit method, that is ok. But back pagination can't be easily done, because we only have endBefore, and endAt method, and how can we get last n elements from given document? I know realtime database have method limitToLast. Is there any query like this for firestore? (Also I need to implement multiple sorting, so getting last documents with "ASC" or "DESC" sorting will not work) Help much appreciated.

谢谢!

推荐答案

相当于 Cloud Firestore 中 Firebase 实时数据库中的 limitToLast(...) 操作是对数据进行降序排序 (这在 Firestore 中是可能的),然后只是 limit(...).如果您在执行此操作时遇到问题,请更新您的问题以显示您已完成的操作.

The equivalent to the limitToLast(...) operation from the Firebase Realtime Database in Cloud Firestore is to order the data descending (which is possible in Firestore) and then just limit(...). If you're having problems implement this, update your question to show what you've done.

我同意这是用于反向分页的次优 API,因为您以相反的顺序接收项目.

I agree that this is a sub-optimal API for back-pagination, since you're receiving the items in reverse order.

这篇关于Firestore 分页 - 是否有与 firebase 的 limitToLast 兼容的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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