使用 Firebase 进行分页/无限滚动 [英] Pagination/Infinite Scroll with Firebase
本文介绍了使用 Firebase 进行分页/无限滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有使用 childByAutoId()
创建的节点的子节点.我正在尝试对在 TableView 中使用它进行分页,但我不知道如何.
I have sub-nodes of a node which I created with childByAutoId()
. I am trying to do pagination for using it in TableView however I couldn't figure out how.
我的数据库如下所示:
- items
-KKM7Fv8H7dCiD2xChYB
- userID : 1231231
-KKM7Fv8H7dCiD2MVaVt
-KKM7Fv8H7dCiDFJfska
我可以给它一个每页项目数"并相应地检索数据的方法吗?进行无限滚动/分页的最佳方法是什么
Is the a way that I can give it a 'items per page count' and retrieve data accordingly? What is the best way of doing infinite scroll/pagination
items.queryOrderedByChild("userId").queryEqualToValue(key).observeEventType(.ChildAdded, withBlock: { snapshot in
推荐答案
需要在每个子节点上加上最后的时间戳,然后查询
You need to add last timestamp with each sub node and then query
firebaseRef.child("user_id").queryOrdered(byChild: "timestamp").queryEnding(atValue: lastTimeStamp - 1).queryLimited(toLast: 10).observe(.value, with: { (snapshot) in })
这篇关于使用 Firebase 进行分页/无限滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文