如何在Firebase的iOS SDK上执行分页查询? [英] How do I perform a pagination query on Firebase's iOS SDK?

查看:91
本文介绍了如何在Firebase的iOS SDK上执行分页查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这是我的模特。

  messagesRef = Firebase(url:https://+ CONSTANTS.FirebaseDB +.firebaseio.com / messages / 1: ($)
messagesRef.queryLimitedToLast(5).observeEventType(FEventType.ChildAdded,withBlock:{(snapshot)in
self.message_list.append(snapshot)// it works。
}) ;
});

我的代码工作 - 得到最后5条消息(8-12)。



但是,如果我有一个函数查询接下来的5条消息(2-6)呢?有一个开始和抵消。我如何查询这个?

解决方案

消息库.firebaseio.com / messages / 1:1000)messagesRef
.queryOrderedByKey()
.queryStartingAtValue(5)
.queryEndingAtValue(10)
.observeEventType(FEventType.ChildAdded ,withBlock:{(snapshot)in self.message_list.append(snapshot)});

这是黑暗中的一种镜头,但它似乎应该基于文档< a href =https://www.firebase.com/docs/ios-api/Classes/Firebase.html#//api/name/queryStartingAtValue> https://www.firebase.com/docs/ios-api /Classes/Firebase.html#//api/name/queryStartingAtValue :


This is my model.

messagesRef = Firebase(url: "https://"+CONSTANTS.FirebaseDB+".firebaseio.com/messages/1:1000")
    messagesRef.queryLimitedToLast(5).observeEventType(FEventType.ChildAdded, withBlock: { (snapshot) in
        self.message_list.append(snapshot) // it works.
    });
});

My code works -- it gets the last 5 messages (8-12).

However, what if I have a function query the next 5 messages (2-6)? With a start and offset. How can I query this?

解决方案

messagesRef = Firebase(url: "https://"+CONSTANTS.FirebaseDB+".firebaseio.com/messages/1:1000")messagesRef
.queryOrderedByKey()
.queryStartingAtValue(5)
.queryEndingAtValue(10)
.observeEventType(FEventType.ChildAdded, withBlock: { (snapshot) in self.message_list.append(snapshot) });

This is kind of a shot in the dark but it seems like it should work based on documentation here https://www.firebase.com/docs/ios-api/Classes/Firebase.html#//api/name/queryStartingAtValue:

这篇关于如何在Firebase的iOS SDK上执行分页查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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