Zulu时间的OrderBy筛选器未按预期工作

时间:2019-04-04 05:14:22

标签: angularjs

我正在尝试在下面的latest中将时间null过滤到HTML。时间格式为Zulu(UTC)格式,即'2017/04/01T00:00:00.000Z'

<li ng-repeat="contact in $ctrl.contacts | orderBy: 'LastChatTime' | filter : searchContact track by $index">

当我这样做时。在存在时间的记录中,以相反的顺序排序,然后出现空记录。 例如:

 1. '2017/03/31T13:00:00.000Z'  
 2. '2017/04/01T00:00:00.000Z'  
 3. `Null`

代替:

 1. '2017/04/01T00:00:00.000Z' 
 2. '2017/03/31T13:00:00.000Z' 
 3. `Null`

1 个答案:

答案 0 :(得分:2)

如果您发现记录按升序排列,即orderBy的行为。

在这里,您需要按降序对contacts进行排序。

您可以尝试以下代码,

<li ng-repeat="contact in $ctrl.contacts | orderBy: '-LastChatTime' | filter : searchContact track by $index">
-前的

LastChatTime将按降序对联系人进行排序

注意:这不会考虑空值

要在排序时支持空值,可以在下面尝试

<li ng-repeat="contact in $ctrl.contacts | orderBy: '[!LastChatTime, -LastChatTime]' | filter : searchContact track by $index">