[英]Iterating array of object in angular ng-repeat
I have an object like this 我有一个这样的物体
var questions= [{ QuestionId:"1",
QuestionName:"loreum ispum?",
Answers: [{option:"A",Score:10},
{option:"B",Score:10}
]
},
{ QuestionId:"2",
QuestionName:"loreum ispum?",
Answers: [{option:"A",Score:10},
{option:"B",Score:10}
]
}]
Iterating through ng-repeat 通过ng-repeat迭代
<ul ng-repeat="question in vm.questions">
<div class="">{{question.QuestionName}}</div>
<input type="text" ng-model="getdetails.QuestionId" ng-value="question.QuestionId" style="display:none"/>
<li ng-repeat="answer in question.Answers track by $index">
<input type="radio" name="questionId_[$index]">" ng-model="getdetails.Score" ng-value="answer.Score" />
</li>
<button class="btn btn-success no-broder-radius" ng-click="change(getdetails)">Submit</button>
</ul>
and clicking on submit button I need to get the Question id and selected input value. 然后单击提交按钮,我需要获取问题ID和选定的输入值。
Controller : 控制器:
$scope.getdetails={};
$scope.change=function(getDetails) {
// I am getting only input radio value not getting question id
}
I am getting only input radio value not getting question id 我只获得输入单选值而不得到问题ID
If getDetails
is a $scope
variable then you can directly access it in your controller, you don't need to pass it from view. 如果
getDetails
是$scope
变量,则可以直接在控制器中访问它,而无需从视图中传递它。
Try this: 尝试这个:
<ul ng-repeat="question in vm.questions">
<div class="">{{question.QuestionName}}</div>
<input type="text" ng-model="getDetails.QuestionId" ng-value="question.QuestionId" style="display:none"></input>
<li ng-repeat="answer in question.Answers track by $index">
<input type="radio" name="questionId_[$index]">" ng-model="getdetails.Score" ng-value="answer.Score" />
</li>
<button class="btn btn-success no-broder-radius" ng-click="change(question)">Submit</button>
</ul>
Now in change function, you will have access to the full object. 现在,在更改功能中,您将可以访问整个对象。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.