【问题标题】:Firebase list order byFirebase 列表顺序
【发布时间】:2017-12-14 02:00:56
【问题描述】:

我有一个 firebase 列表,我试图按“时间”节点对其进行排序。我怎样才能在打字稿中做到这一点?谢谢!

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;
        });
     });
  }

【问题讨论】:

  • 您要订购哪些代码 // 获取聊天参考或 // 获取登录用户的聊天列表
  • 好像你在使用 angularfire2

标签: typescript firebase ionic-framework


【解决方案1】:

考虑到您正在使用 Angularfire2 ,您所要做的就是这个。

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-07
    • 1970-01-01
    • 2014-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-01
    相关资源
    最近更新 更多