我有以下HTML,我希望通过newestComment按时间顺序对它们进行排序:
<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"
}
}
不管我做什么,我似乎都无法弄清楚如何对其进行排序-它始终只是按数组的顺序出现。有什么帮助吗?
最佳答案
orderBy
过滤器仅适用于对象数组,不适用于对象本身。参见文档here。