【问题标题】:ionic2/angular 2 How to show comment replies in descending order based on timeionic2/angular 2 如何根据时间降序显示评论回复
【发布时间】: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 来订购它们

标签: json angular ionic2


【解决方案1】:

Angular 不提供orderBy 管道。见here。

所以你必须自己写。或许这篇文章可以帮到你:Angular 2. How to apply orderBy?

【讨论】:

  • 感谢您的回复。我使用一个名为angular-pipes 的库。所以我不需要为此写我的客户管道。
猜你喜欢
  • 1970-01-01
  • 2018-12-15
  • 1970-01-01
  • 2015-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-07
相关资源
最近更新 更多