Firebase列表顺序依据

时间:2017-07-10 10:59:13

标签: typescript firebase ionic-framework

我有一个火力列表,我试图通过"时间"节点。我怎么能用打字稿呢?谢谢!

page.ts:

// Get Chat Reference
    chatsProvider.getChatRef(this.company, this.uid, this.interlocutor)
    .then((chatRef:any) => {  
        this.chats = this.db.list(chatRef);
    });

ChatProvider.ts

// get list of Chats of a Logged In User
  getChats() {
    return this.up.getCompany().then(company => {
        return this.up.getUid().then(uid => {
            let chats = this.db.list(`/companies/${company}/users/${uid}/chats`);
            return chats;
        });
     });
  }

1 个答案:

答案 0 :(得分:1)

考虑到您使用的是Angularfire2,您只需要这样做。

this.chats = this.db.list(chatRef, {
  query: {
    orderByChild: "time"
  });
  

如果您想按降序排列列表,我建议您将时间存储为负时间戳

相关问题