2015-08-17 158 views
0

我在Firebase服务器中有一组歌曲。 每首歌都有lastCommentAt属性,它是时间戳。Firebase按日期排序(时间戳) - Firebase

我想检索到当前时间最近的lastCommentAt时间的歌曲顺序。

这是我的火力地堡规则:

{ 
    "rules": { 
     ".read": true, 
     ".write": "auth != null", 
     "songs": { 
      ".indexOn": ["lastCommentAt"] 
     } 
    } 
} 

Songs feed example - CodePen

我不能使用orderByChild()。这使得奇怪的问题:

  • Uncorrect为了

  • loadMore()加载相同的2首歌曲的循环。这意味着无限制的 歌曲列表。

Songs feed with orderByChild() example - CodePen

回答

0

我怀疑你的问题的根本原因是缺乏的startAt()的效果的认识连同orderByChild()使用时。欲了解更多信息,请阅读Firebase documentation on queries

如果使用orderByChild("lastCommentAt")那么startAt()功能适用到实例的ID,但每个实例的lastCommentAt财产。

所以一旦你已经添加orderByChild("lastCommentAt")那么startAt()需要有第一个参数是你想获得和第二个参数是你想获得最后lastCommentAt值的第一个lastCommentAt值。