我有一个聊天程序。当应用程序加载时,我通过执行以下操作来加载最后 5 条消息:
var chatRef = new Firebase("https://xxxx.firebaseio.com/chat/");
$scope.query = chatRef.orderByChild("Datestamp").limitToLast(5);
$scope.chatList = $firebaseArray($scope.query);
我想为用户提供加载更多以前消息的选项。但我不知道如何加载接下来的 5 条消息。我正在尝试类似的事情但没有成功:
$firebaseArray(chatRef.orderByChild("Datestamp").endAt($scope.chatList[0].Datestamp).limitToFirst(5)).$loaded(function (data) {
data.forEach(function (d) {
$scope.chatList.push(d);
});
});
所以基本上我的数据集如下所示:
消息1
消息2
消息3
消息4
消息5
消息 6
消息7
消息 8
消息 9
消息 10。
当我加载应用程序时,我说 limitToLast(5),它会拉动:
消息 6
消息7
消息 8
消息 9
消息 10
现在我想加载之前的 2 条记录,
消息4
消息 5
我怎样才能做到这一点?
最佳答案
您正在寻找endAt()
。您需要传入收到的第一条消息的值,因此在您的例子中是消息 6 的时间戳。
chatRef.orderByChild("Datestamp").endAt(message6.Timestamp).limitToLast(3);
您将在已显示的结果中收到消息 6。因此,您需要跳过结果中的最后一条消息。
关于angularjs - Firebase - limitToLast(5),然后加载以前的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34169675/