【问题标题】:multiple ng-repeat count array length with condition具有条件的多个 ng-repeat 计数数组长度
【发布时间】:2017-08-03 10:38:19
【问题描述】:

这是我的角度代码:

//first ng repeat
$http.get(server_base_url + "api/v1/testsectionlist/" + $scope.instslug + "/" + $scope.test Slug)
`enter code here`
.success(function(section Data) {
  $scope.section Data = section Data;
})
//second ng repeat 
$http.get(server_base_url + "api/v1/correctques/" + $scope.testSlug + "/" + $scope.test Id)
  .success(function(correct ques) {
    $scope.correct cues = correct ques;
    //console.log($scope.correct ques); 
  })

<div class="col-xs-4" style="padding-left: 0px; padding-right: 0px;" ng-repeat="sectionView in sectionData">
  <div class="card" style="height: 175px;">
    <div class="card-heading">
      <h2 style="text-transform: uppercase;">{{sectionView.section}}</h2>
    </div>
    <div class="list-group list-group-lg no-bg">
      <a href="" class="list-group-item text-ellipsis">
        <span class="pull-right" ng-repeat="sectionscoreData in correctques">
   <span ng-if="sectionView.sectionId == sectionscoreData.sectionId && sectionscoreData.answer == sectionscoreData.selectOption">{{sectionscoreData.sectionId}}</span>
        </span>
      </a>
    </div>

我正在使用两个 ng-repeat 并检查多个条件,但不计算我的跨度 ng-if 条件中的总 ID。 谁能帮我计算ng-if 多个条件的数组长度并使用多个 ng 重复?

提前致谢。

【问题讨论】:

  • 你必须更清楚你在这里想要做什么。您是否不小心删除了一些问题?
  • 使用嵌套的 ng-repeat 会大大降低性能。将它们分开。

标签: php html angularjs angularjs-ng-repeat angular-ng-if


【解决方案1】:

而不是使用 ng-if 您应该在 ng-repeat 上使用过滤器,以便它只包含匹配的值。最后一项的 $index 将为您提供计数,但最好创建一个过滤项的数组并查看它的长度。有关如何执行此操作的详细信息,请参阅此问题和答案:Using ng-repeat and filter, how to tell which items are visible?。

【讨论】:

    猜你喜欢
    • 2014-03-25
    • 1970-01-01
    • 2019-02-28
    • 1970-01-01
    • 2013-08-06
    • 2016-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多