ng-repeat中的动态变量ng-repeat

时间:2015-08-25 15:22:08

标签: javascript angularjs ng-repeat

我在其他ng-repeat指令中有ng-repeat。 我尝试使用第一个中的键进行第二次ng-repeat动态,但这种语法不起作用。有没有办法让它发挥作用?可能有不同的表示法吗?

<div class="entry" ng-repeat="(key, choice) in choices">
    <div >
        <div ng-repeat="option in fields['user_' + key].options | filter : {v:choices[key].junior.v}" class="box-content-value">{{option.l}}</div>
    </div>
</div>

过滤器没有问题,因为它是一个对象,另一方面fields.user_$不是,我必须组合字符串+变量才能使它工作。

评论选择中的请求是不相关的,并且只是js对象的简单数组

另一方面,

字段看起来像这样

"fields": {
    "user_0": {
        "display": true,
        "options": [{
            "k": 0,
            "v": "",
            "l": "Please select"
        }, {
            "k": 1,
            "v": "male",
            "l": "Male"
        }, {
            "k": 2,
            "v": "female",
            "l": "Female"
        }],
        "read_only": false
    }
}

所以我必须显示fields.options.l只有fields.option.v属性的完整值。这就是为什么我在这里使用过滤器。

1 个答案:

答案 0 :(得分:0)

使用$index代替key

<div class="entry" ng-repeat="choice in choices">
    <div >
        <div ng-repeat="option in fields['user_' + $index].options | filter : {v:choice.junior.v}" class="box-content-value">{{option.l}}</div>
    </div>
</div>
相关问题