{{thread.newestComment}} 数据(messag-6ren">
gpt4 book ai didi

javascript - 无法弄清楚为什么 ng-repeat 不排序

转载 作者:行者123 更新时间:2023-11-30 17:25:39 25 4
gpt4 key购买 nike

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

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

最佳答案

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

关于javascript - 无法弄清楚为什么 ng-repeat 不排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24331584/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com