0

我似乎无法正确订购我的 firebase 滚动条。我在 Firebase 中有一些帖子,我想让 Firbase 将我的帖子从最近到最旧的顺序排列。然而,它正在做相反的事情。这些帖子正在从旧到新排序。

var ref = new Firebase("https://feburl");
var posts= ref.child('posts');
// create a scrollable reference
var scrollRef = new Firebase.util.Scroll(posts, 'created');

我正在使用这个:https ://github.com/firebase/firebase-util

可以在此处找到使用示例:https ://gist.github.com/katowulf/7adb5775dce44cbbba0a

4

1 回答 1

1

一种可能的解决方案是在您将数据存储在 Firebase 中时为其添加时间戳,使用 Firebase 的安全性和规则按时间戳索引该数据,然后根据该时间戳检索数据。

在安全和规则方面:

{
    "rules": {
        "posts": { 
            ".indexOn": "timestamp"
        }   
}

然后,当您访问数据时:

var posts= ref.child('posts').orderByChild("timestamp").limitToLast(XX);

虽然,我还没有使用无限滚动库对此进行测试。

于 2016-05-17T19:15:12.673 回答