1
 <table class="table table-bordered">
      <tr ng-repeat="x in AppliedJob">
    <td>{{x.JobName}}</td>
 <td>  <span class="dropdown" ng-repeat="y in AppliedCenter|  unique: 'Location' " ng-if="y.JobName==x.JobName">
 {{$index+1}}){{y.Location}}                      
 </span> </td></tr> </table>

上述代码的输出

1) Tester    :  1)India 2)USA 3)Australia
2) Developer :  4)Japan 5)China

所需输出

1) Tester    :  1)India 2)USA 3)Australia
2) Developer :  1)Japan 2)China

我想设置$Index1.

4

1 回答 1

0

发生这种情况是因为您正在使用ng-if不影响数组及其索引进行过滤,它只是从 DOM 中删除元素。您应该使用过滤器而不是y.JobName==x.JobName比较,ng-if因此您的ng-repeat表达式应该是这样y in AppliedCenter | unique: 'Location' | filter: { JobName: x.JobName }的。参见示例:

angular
.module('Test', [])
.controller('TestController', ['$scope', function($scope) {
  $scope.cities = ["New York", "LA"];
  $scope.jobs = [{ name: "QA", city: "New York"}, { name: "Frontend", city: "New York"}, {name: "Backend", city: "New York"}, {name: "DBA", city: "LA"}, { name: "QA", city: "LA"}];
  }]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
<div ng-app="Test">
  <div ng-controller="TestController">
    <table>
      <tr ng-repeat="city in cities">
        <td ng-bind="city"></td>
        <td>
          <span ng-repeat="job in jobs | filter:{city: city}">{{($index + 1) + ")" + job.name}} </span>
        </td>
      </tr>
     </table>
  </div>
</div>

于 2016-08-31T05:49:04.067 回答