【发布时间】:2017-07-09 00:27:02
【问题描述】:
简而言之:
在 ionic2 中显示 cmets 的最佳方式是什么,尤其是当它有回复时。我需要根据他们的时间显示回复。
++++++++++++++++++++++++++++++++
详细问题:
我有以下 json 格式的数据。
这是 cmets 的列表。在这个例子中,items 标签下有 19 个 cmets。
http://www.jsoneditoronline.org/?id=47b282c498505ed25869dc36f5f3bd58
评论已根据发布日期排序。
现在,在第 10 个项目 ID 上,有两条对此评论的回复。
我正在寻找一种根据发布时间订购此回复的方法。
下面是我的html: 这里videoComments =上面指定的json数据
我尝试使用angualr-pipes orderBy 管道,但这对我不起作用,还有其他方法吗?
<ion-list>
<ion-item *ngFor="let comment of videoComments">
<!-- here i Print the details what is required , next if there are any reply i would like to show them-->
<div *ngIf="comment.snippet.totalReplyCount != 0">
<ion-list>
<ion-item *ngFor="let reply of comment.replies.comments | orderBy: 'publishedAt'">
<!-- Above orderBy pipe is not working , may be my syntax is wrong -->
<!-- I would like to show replies in ascending order of when it was submitted-->
<!-- Details of replies will be shown here -->
</ion-item>
</ion-list>
</div>
</ion-item>
</ion-list>
【问题讨论】:
-
我不知道它是否可以帮助你,但尝试使用 MomentJS 并将你的日期转换为 Unix 时间,这样它将是一个像 1499560680 这样的数字,所以在显示之前进行简单的排序就可以了把戏
-
@Gabriel,谢谢你的建议。我认为无论我使用哪个标签,OrderBy Pipe 都不会在任何标签中应用。因为当我执行 orderBY: '-publishedAt' 时,结果没有区别。
-
你可以使用 lodash 来订购它们