【问题标题】:$index not working properly with OrderBy$index 不能与 OrderBy 一起正常工作
【发布时间】: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


【解决方案1】:

先保存

var len = (currDateByMsg[msgDate.strDate].length-1);

然后

$index + len

在 html 中。

【讨论】:

    猜你喜欢
    • 2018-11-10
    • 2014-07-01
    • 1970-01-01
    • 2016-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多