本文介绍了如何获取在NG-重复previous项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想要生成只有在当前项目已经从previous项目的一些不同领域的一些HTML模板。我怎样才能访问previous项目在NG-重复?

I have a template in which I want to generate some HTML only if the current item has some different fields from the previous item. How can I access the previous item in an ng-repeat?

推荐答案

您可以不喜欢

<div ng-app="test-app" ng-controller="MyController">
    <ul id="contents">
      <li ng-repeat="content in contents">
          <div class="title">{{$index}} - {{content.title}} - {{contents[$index - 1]}}</div>
      </li>
    </ul>
</div>

JS

var app = angular.module('test-app', []);

app.controller('MyController', function($scope){
    $scope.contents=[{
        title: 'First'
    }, {
        title: 'Second'
    }, {
        title: 'Third'
    }]
})

演示:

注意: $指数是指令数组,它可能比范围数组不同。使用内联变量来访问正确的阵列。

Be careful: $index is for the directive array, which may be different than the scope array. Use an inline variable to access the correct array.

<li ng-repeat="content in (correctContents = (contents | orderBy:'id'))">
  {{ correctContents[$index - 1] }} is the prev element
</li>

如果您筛选或排序依据,内容[$指数]!=含量

If you filter or orderBy, contents[$index] != content.

这篇关于如何获取在NG-重复previous项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:08