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

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

问题描述

是否有一种方法可以通过Firestore实现后向分页? 我正在努力实现与Firestore的分页,并且对Firestore的查询有限.可以使用 startAt limit 方法进行前向分页,可以.但是后向分页并不是一件容易的事,因为我们只有 endBefore endAt 方法,以及如何从中获取最后的 n 个元素给定文件?我知道实时数据库具有方法 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天全站免登陆