无法弄清楚为什么ng-repeat没有排序

时间:2014-06-20 16:15:20

标签: javascript angularjs angularjs-ng-repeat

我有以下HTML,我想根据最新评论按时间顺序排序:

<div class="list list-inset"
    ng-repeat="(threadId, thread) in messageThreads | orderBy:'thread.newestComment'"
    ng-if="thread.newestComment > messageClearTime">
    <div class="item item-divider">
        {{thread.newestComment}}
    </div>
</div>

数据(messageThreads)就是这个,其中threadId作为键,而newestComment作为时间戳:

{ "5381897" : {
      "newestComment" : 1403280014,
      "title" : "asdf"
    },
  "5595015" : {
      "newestComment" : 1403192555,
      "title" : ""
    },
  "5761260" : {
      "newestComment" : 1403126044,
      "title" : ""
    },
  "5838498" : {
      "newestComment" : 1403279962,
      "title" : "Share Test"
    }
}

无论我做什么,我似乎无法弄清楚如何对它进行排序 - 它总是按照数组的顺序出现。任何帮助?

1 个答案:

答案 0 :(得分:2)

orderBy过滤器仅适用于对象数组,不适用于对象本身。请参阅文档here