检查ng-repeat中的项目是否已包含值

Vik*_*kas 8 javascript angularjs angularjs-ng-repeat angular-ng-if

我有问题和答案的JSON字符串绑定在ng-repeat中,现在问题是我想在ng-repeat中显示一次问题和所有多个答案.这是我的数据.

{Answer:"White",AnswerID:967,answer_type:"RADIO",fullquestion:"Your Race",id:6}{Answer:"African American",AnswerID:968,answer_type:"RADIO",fullquestion:"Your Race",id:6}{Answer:"Asian",AnswerID:969,answer_type:"RADIO",fullquestion:"Your Race",id:6}
Run Code Online (Sandbox Code Playgroud)

我正在展示的观点

 <div ng-repeat="hrq in HrqQuestions">
            <div class="list card normal">
                <div class="item item-body item-divider">                    
                    <p ng-bind="hrq.fullquestion"></p>                       
                </div>
                <label class="item item-input" ng-show="hrq.answer_type=='FREETEXT'">
                    <input ng-model="hrq.Answer" name="name" type="text">
                </label>
                <div ng-if="hrq.answer_type=='RADIO'">
                    <ion-radio ng-click="selectedAnswer(hrq.AnswerID,hrq.Answer)" name="radio1" ng-value="hrq.AnswerID">{{hrq.Answer}}</ion-radio>
                </div>
            </div>
        </div>
Run Code Online (Sandbox Code Playgroud)

但这会多次将所有问题与答案联系起来

     Q.Your Race
           White Your Race
     Q.Your Race
           African American Your Race
     Q.Your Race
           Asian
Run Code Online (Sandbox Code Playgroud)

但我需要

     Q. Your Race
           White Your Race
           African American Your Race
           Asian
Run Code Online (Sandbox Code Playgroud)

如果有人能帮助我,我将非常感激

Man*_*u V 3

尝试这个,

  1. 将“HrqQuestions”更改为数组
  2. 使用“id”对您的问题进行分组
  3. 并重复分组问题的值。像这样,

angular.module('app',['angular.filter']).controller('MainController', function($scope) {
  $scope.HrqQuestions = [
      {Answer:"White",AnswerID:967,answer_type:"RADIO",fullquestion:"Your Race",id:6},
      {Answer:"African American",AnswerID:968,answer_type:"RADIO",fullquestion:"Your Race",id:6},
      {Answer:"Asian",AnswerID:969,answer_type:"RADIO",fullquestion:"Your Race",id:6}
    ];
 });
Run Code Online (Sandbox Code Playgroud)
<!DOCTYPE html>
<html ng-app="app">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.22/angular.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/angular-filter/0.5.4/angular-filter.js"></script>

<body ng-controller="MainController">
  <div ng-repeat="(key, value) in HrqQuestions | groupBy: 'id'">
    <div><strong>Id:</strong> {{ key }}</div>
     <p ng-repeat="v in value">
       <strong>Answer {{ $index + 1}}</strong>. {{ v.Answer }}
     </p>
  </div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)