【发布时间】:2016-08-19 10:17:37
【问题描述】:
我有 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}
查看我正在显示的
<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>
但这会将所有问题多次与答案绑定
Q.Your Race
White Your Race
Q.Your Race
African American Your Race
Q.Your Race
Asian
但我需要喜欢
Q. Your Race
White Your Race
African American Your Race
Asian
如果有人能帮我解决这个问题,我将非常感激
【问题讨论】:
-
一个想法是将 HrqQuestions 对象转换为您想要的格式。
标签: javascript angularjs angularjs-ng-repeat angular-ng-if