I'm using an ng-repeat to show the sections of a form, inside every section I must show the questions so I'm using one nested ng-repeat but I don't know how to show (or why not shows) the values.
我正在使用ng-repeat来显示表单的各个部分,在每个部分内我必须显示问题所以我使用一个嵌套的ng-repeat但我不知道如何显示(或为什么不显示)值。
This is a sample json I'm workin with:
这是我正在研究的一个样本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
}]
}
And this is my view:
这是我的观点:
<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 is where I store the json form the web service in the controller. On this case I use a different json structure than in other questions
Questionstest是我将json格式存储在控制器中的Web服务的地方。在这种情况下,我使用不同于其他问题的json结构
2 个解决方案
#1
1
try this.
尝试这个。
<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>
#2
1
The second ng-repeat
appears to be trying to loop over a non-existent variable. Given you're inside the loop for the section you should change your second repeat to something like:
第二个ng-repeat似乎试图遍历一个不存在的变量。鉴于你在该部分的循环中,你应该将你的第二次重复改为:
<div class="panel-body" ng-repeat="question in section.questions track by $index">
{{ question.statement }} <!-- .statement -->
</div>
#1
1
try this.
尝试这个。
<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>
#2
1
The second ng-repeat
appears to be trying to loop over a non-existent variable. Given you're inside the loop for the section you should change your second repeat to something like:
第二个ng-repeat似乎试图遍历一个不存在的变量。鉴于你在该部分的循环中,你应该将你的第二次重复改为:
<div class="panel-body" ng-repeat="question in section.questions track by $index">
{{ question.statement }} <!-- .statement -->
</div>