angular 上的嵌套 ng-repeat 不起作用

Nested ng-repeat on angular is not working

我正在使用 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 是我在控制器中存储 json 表单 Web 服务的地方。在这种情况下,我使用了与其他问题

不同的 json 结构

第二个 ng-repeat 似乎试图循环一个不存在的变量。鉴于您在该部分的循环内,您应该将第二次重复更改为:

<div class="panel-body" ng-repeat="question in section.questions track by $index">
    {{ question.statement }} <!-- .statement -->
</div> 

试试这个。

<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>