【发布时间】:2016-12-19 14:00:56
【问题描述】:
<div ng-repeat="msg in currDateByMsg[msgDate.strDate]|orderBy :'-SendMsgDate':true">
<div ng-if="!msg.currentUser">
<div data-ng-if="$first || (currtDateByMsg[msgDate.strDate][$index].userId !=
currDateByMsg[msgDate.strDate][$index -1].userId)">
<img class="img-circle" ng-src="{{msg.iconPath}}"/>
</div>
</div>
<div>{{msg.userMessage}}</div>
</div>
当多个消息来自同一用户时,我想跳过图像(即仅显示一个图像)。我以相反的顺序进行迭代,但 $index 值从 0 开始。所以我也如何反转索引值.
【问题讨论】:
-
$index 是重复元素的迭代器偏移量(0..length-1),它总是从 0 开始,order by 将通过 SendMsgDate 反转数据。所以在 $index = 0 你会得到最后一项。
-
检查this question,英里的答案应该可以帮助您解决问题
标签: javascript angularjs angularjs-orderby