ng-repeat 内的动态变量 ng-repeat
dynamic variable ng-repeat inside 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_$
不是,我必须组合字符串 + 变量才能使其工作。
comment-choices 中的请求不相关,只是 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
属性。这就是为什么我在这里使用过滤器。
使用$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>
我在其他 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_$
不是,我必须组合字符串 + 变量才能使其工作。
comment-choices 中的请求不相关,只是 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
属性。这就是为什么我在这里使用过滤器。
使用$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>