我正在使用 ng-repeat 来显示表单的各个部分,在每个部分中我必须显示问题,因此我使用一个嵌套的 ng-repeat 但我不知道如何显示(或者为什么不显示)值。
这是我正在使用的示例 json:
{
"section": [{
"name": "Seccion 1",
"questions": [{
"statement": "Primera pregunta",
"id": 1
}, {
"statement": "Pregunta 3",
"id": 3
}, {
"statement": "Pregunta 4",
"id": 4
}],
"id": 1
}, {
"name": "Seccion 2",
"questions": [{
"statement": "Segunda pregunta",
"id": 2
}],
"id": 2
}]
}
这是我的观点:
<div class="panel panel-default" ng-repeat="section in questionsTest track by $index">
<div class="panel-heading">
<h1>{{ section.name }}</h1>
<h3 class="panel-title">{{ section.name }}. {{ section.id }}</h3>
</div>
<div class="panel-body" ng-repeat="question in questions.section.questionsTest track by $index">
{{ question[$index].statement }} <!-- .statement -->
</div>
</div>
Questionstest 是我在 Controller 中存储来自 Web 服务的 json 的位置。在本例中,我使用与其他问题不同的 json 结构
最佳答案
试试这个。
<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.id }}</h3>
</div>
<div class="panel-body" ng-repeat="question in section.questions">
{{ question.statement }} <!-- .statement -->
</div>
</div>
关于javascript - Angular 上的嵌套 ng-repeat 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41475837/