我使用了3个嵌套的ng-repeat,用于显示几个问题和她的相应答案。直到这里都很好,但我必须创建一个表单来保存答案,那么适当的方法是什么?我与这个测试:从JSON动态表单创建
<form>
<div class="panel panel-default" ng-repeat="section in questionsTest">
<div class="panel-heading">
<h1>{{ section.name }}</h1>
<h3 class="panel-title">{{ section.name }}. {{
section.description }}</h3>
</div>
<div class="panel-body" ng-repeat="question in section.questions">
{{ question.statement }}
<div ng-repeat="answer in question.answers">
<label class="radio-inline"> <input type="{{ answer.type }}" ng-model="test.idRadioButton"
name="{{ question.id }}" id="{{ answer.id }}" value="{{ answer.id }}">
{{ answer.valor }}
</label>
</div>
</div>
</div>
</form>
这是JSON:
{
"section": [{
"name": "Sección 1",
"questions": [{
"statement": "Primera pregunta",
"answers": [{
"valor": "1",
"id": 3,
"type": "radio"
}, {
"valor": "2",
"id": 4,
"type": "radio"
}, {
"valor": "3",
"id": 7,
"type": "radio"
}, {
"valor": "4",
"id": 8,
"type": "radio"
}, {
"valor": "5",
"id": 9,
"type": "radio"
}, {
"valor": "6",
"id": 10,
"type": "radio"
}, {
"valor": "7",
"id": 11,
"type": "radio"
}],
"id": 1
}, {
"statement": "Pregunta 3",
"answers": [{
"valor": "Si",
"id": 1,
"type": "radio"
}, {
"valor": "No",
"id": 2,
"type": "radio"
}],
"id": 3
}, {
"statement": "Pregunta 4",
"answers": [{
"valor": "Si",
"id": 1,
"type": "radio"
}, {
"valor": "No",
"id": 2,
"type": "radio"
}],
"id": 4
}],
"description": "description",
"id": 1
}
它不会在所有的工作,当我点击第一个问题,点击所有其他问题得到也。我是有角度的新手,我不知道如何面对这个。由于
“工作”了,但我不能存储所有点击单选按钮。这是我有我的控制器:
$scope.question = {};
$scope.testing = function(){
console.log($scope.question);
};
测试功能是作秀存储在$ scope.question控制台上的值。
更改ID为好,不只是名字?也张贴JSON的例子,以帮助破译你的问题 – MiltoxBeyond
@MiltoxBeyond我已经复制了JSON和试图改变ID,但仍然无法正常工作 – proktovief