获取动态字段和单选按钮的值

时间:2016-11-02 11:43:27

标签: angularjs

你能就这个问题提出想法或建议吗? 我每个问题创建四个单选按钮(基本上是一个多选题),它们是动态生成的。如果我创建了3个多项选择题,我的问卷中将显示3个多项选择。 如果存在3个选择题,则3个问题x 4个单选按钮= 12个单选按钮。这意味着我有一个由4个单选按钮组成的3组无线电组。我的问题,如何才能获得3组无线电组中选择的值?

php code:
          echo "<li><input type='radio' name='radio' value='a' class='answer multiple'/>choice</li>";
          echo "<li><input type='radio' name='radio' value='b' class='answer multiple'/>choice</li>";
          echo "<li><input type='radio' name='radio' value='c' class='answer multiple'/>choice</li>";
          echo "<li><input type='radio' name='radio' value='d' class='answer multiple'/>choice</li>";

1 个答案:

答案 0 :(得分:0)

您可以使用ng-repeat创建多个问题,然后使用嵌套的ng-repeat来显示选项

Here is the plnkr for the same

  <div ng-repeat="question in questions">
    <p><label>{{question.title}}</label></p>
    <div ng-repeat="choice in question.choices"><input type="radio" ng-name="question.title" ng-model="radioValue[$parent.$index]" ng-value="choice">{{choice}} </div>
  </div>

AngularJS代码

$scope.questions = [{id:1, title:'Question 1', choices:['Apple','Orange','Mango','Guava']},
                    {id:2, title:'Question 2', choices:['Apple2','Orange2','Mango2','Guava2']},
                    {id:3, title:'Question 3', choices:['Apple3','Orange3','Mango3','Guava3']}]
   $scope.radioValue =[];