0

我以角度在另一个数组中循环一个数组。

fields:
            [
                {
                    label: 'First Name',
                    name: 'firstname',
                    key: '',
                    type: 'text',
                    //fixa requierd i templatesen
                    required: true
                },
                {
                    label: 'Last Name',
                    name: 'lastname',
                    key: '',
                    required: true,
                },
                {
                    label: 'Email',
                    name: 'email',
                    key: '',
                    required: true,
                    type: 'email',
                },
                {
                    key: 'test',
                    type: 'radio',
                    labels:
                    [
                        {
                            name: 'media',
                            label: 'Media'
                        },
                        {
                            name: 'frilans',
                            label: 'Frilans'

                        }

                    ],
                }
            ],

在循环通过 field.labels 时,我想访问它的兄弟“键”。我尝试使用 $parent 范围,但这将包括整个范围。然后角度不知道它应该使用什么键。

4

1 回答 1

1
<div ng-repeat="field in fields">       
    <div ng-repeat="subfield in field.labels">
        <!-- gets you parent's key -->
        {{field['key']}}
        <!-- you can play around with $index to reach the parent's siblings -->
        <!-- just make sure index is in the range though -->
        {{fields[$parent.$index - 1]['key']}}
        {{fields[$parent.$index + 1]['key']}}
    </div>
</div>
于 2013-09-16T11:50:44.557 回答