我正在尝试使用 Firebase Firestore startAfter()和limit()查询方法实现分页系统。第一个查询成功返回,但第二个查询返回空快照。
这是我的getNextPage()方法:
fun getNextPage(paginationSize : Long) : TrendingRepository {
database.collection("app")
.document("data")
.collection("offers")
.orderBy("discount")
.startAfter(lastVisible)
.limit(paginationSize)
.get().addOnSuccessListener { snapshot ->
Log.i("TrendingRepo", "pagination size : $paginationSize")
val newList = ArrayList<Offer>()
if (!snapshot.isEmpty) {
lastVisible = snapshot.documents[snapshot.size() - 1]
}
for (document in snapshot) {
val item = document.toObject(Offer::class.java)
newList.add(item)
Log.i("TrendingRepo", "at position: ${newList.indexOf(item)} got item: ${item.id}")
}
successListener?.onSuccess(newList)
}.addOnFailureListener {
failureListener?.onFailure(it.localizedMessage)
}
return this
}
这是我的 Logcat:
TrendingRepo: pagination size : 48 // 第一次尝试
TrendingRepo:在位置:0 得到项目:0pqcRzSd06WWlNNmcolu
TrendingRepo:在位置:1 得到了项目:7I7wiSYt5yEBWwN08bqJ
...
TrendingRepo:在位置:45 得到项目:4B3dEPhFLqhKrYpLWYE7
TrendingRepo:在位置:46 得到项目:4ddLqiGe8ReXW8SKq2Q6
TrendingRepo:在位置:47 得到项目:4uVnnGNAmKvGUUHcV01n
TrendingRepo: pagination size : 48 // 第二次尝试
//不再记录,数据为空
qq_笑_17
相关分类