Angularjs 如何使用ng repeat在2个作用域上迭代

Angularjs 如何使用ng repeat在2个作用域上迭代,angularjs,angularjs-scope,angularjs-ng-repeat,Angularjs,Angularjs Scope,Angularjs Ng Repeat,如果我有两个作用域共享一个普通人代码值,我可以使用ng repeat在视图中链接它们吗?我想我要做的是类似于嵌套for循环的事情。 我希望遍历一个范围,同时检查另一个范围是否匹配人员代码,然后如果第二个范围中存在人员代码,则显示另一个按钮 <div ng-repeat="x in model.data | filter: cc.course_code | filter: occ.occurrence | filter: tgn.tutor_group_name | orderBy: 'su

如果我有两个作用域共享一个普通人代码值,我可以使用ng repeat在视图中链接它们吗?我想我要做的是类似于嵌套for循环的事情。 我希望遍历一个范围,同时检查另一个范围是否匹配人员代码,然后如果第二个范围中存在人员代码,则显示另一个按钮

<div ng-repeat="x in model.data | filter: cc.course_code | filter: occ.occurrence | filter: tgn.tutor_group_name | orderBy: 'surname'  | unique: 'PERSON_CODE'" ng-model="x">
  <h4><b>{{ x.forename }} {{x.surname}}</b>  ID: {{x.PERSON_CODE}}</h4>
  <h5>{{x.course_name}}</h5>
  <h5>{{ x.faculty_name }} {{x.area_code}}   </h5>
  <h5>{{x.area_name}}</h5>
  <h5>{{x.tutor_group_name}}</h5>
  <div ng-repeat="d in destinations.data" ng-model="d">
    <div ng-if="(x.PERSON_CODE === d.PERSON_CODE)">
      <div ng-show="d.EMP_DEST_CODE" class="pull-right">
        <a href="#myModal" type="button" class="btn btn-success butt-sz ladda-button" data-target="#myModal" data-toggle="modal" ng-click="editStudent(x.PERSON_CODE);">
          <span class="glyphicon glyphicon-pencil"></span> Edit Destination
        </a>
      </div>
    </div>
  </div>
  <div ng-show="(!d.EMP_DEST_CODE)" class="pull-right">
    <a href="#myModal" type="button" class="btn btn-warning butt-sz ladda-button" data-target="#myModal" data-toggle="modal" ng-click="editStudent(x.PERSON_CODE);">
      <span class="glyphicon glyphicon-plane"></span> Record Destination
    </a>
  </div>
</div>

{{x.forename}}{x.lasname}}ID:{{x.PERSON_CODE}
{{x.course_name}
{{x.faculty_name}{{x.area_code}}
{x.area_name}
{{x.tutor_group_name}
我试过上面的方法,但根本不起作用


如果目的地范围中有相应的条目,并且没有Id,我希望显示绿色按钮。我建议在控制器中编写一个函数,检查传递的条目是否位于目的地,如下所示:

$scope.isDestination = function(p) {
    for(var i = 0; i < $scope.destinations.data.length; i++) {
        if(p.PERSON_CODE == $scope.destinations.data[i].PERSON_CODE) 
            return true;
    }
    return false;
}

您的代码中有什么问题?预期的行为是什么?@Mistalis是的,对不起,我在上面编辑了,代码当前会对每个项目应用一个红色按钮,而不仅仅是那些在目的地范围内没有条目的项目,这是我希望它的行为。所以每个项目只显示一个红色或绿色按钮,为什么要使用两个范围?在单个作用域中获取数据。@Simanchal.panigrahi我确实将其放在一个作用域中,但每当用户保存新数据时,它都会刷新所有用户不常用的用户筛选器,因此我将它们拆分,以便保存新的目标数据不会影响任何其他内容。我不确定这是否正确,但我缺乏想法,在寻找解决方案的压力下谢谢你,这是一个很好的答案,我希望我能想到它,而不是徘徊这么久,它工作得很好再次感谢
<div ng-repeat="x in model.data | filter: cc.course_code | filter: occ.occurrence | filter: tgn.tutor_group_name | orderBy: 'surname'  | unique: 'PERSON_CODE'" ng-model="x">
  ...

  <div ng-if="isDestination(x)"> <!-- isDestination returns true -->
    <a href="#myModal" type="button" class="btn btn-success butt-sz ladda-button" data-target="#myModal" data-toggle="modal" ng-click="editStudent(x.PERSON_CODE);">
      <span class="glyphicon glyphicon-pencil"></span> Edit Destination
    </a>
  </div>

  <div ng-if="!isDestination(x)"> <!-- isDestination returns false -->
    <a href="#myModal" type="button" class="btn btn-danger butt-sz ladda-button" data-target="#myModal" data-toggle="modal" ng-click="editStudent(x.PERSON_CODE);">
      <span class="glyphicon glyphicon-plane"></span> Record Destination
    </a>
  </div>
</div>