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

时间:2021-05-05 21:11:38

I have the following HTML which I which I would like to sort reverse chronologically by the newestComment:

我有以下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>

The data (messageThreads) is this with the threadId as the key and the newestComment as a timestamp:

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

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

No matter what I do I can't seem to figure out how to make it sort--it always just comes out in the order the array is in. Any help?

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

1 个解决方案

#1


2  

The orderBy filter only works on arrays of objects, not on objects themselves. See the docs here.

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

#1


2  

The orderBy filter only works on arrays of objects, not on objects themselves. See the docs here.

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