让我们说
$scope.xs = [1, 2, 3];
$scope.ys = [{"name": "one", "the-number": 1},
{"name": "une", "the-number": 1},
{"name": "two", "the-number": 2},
{"name": "deux", "the-number": 2},
{"name": "three2", "the-number": 3},
{"name": "trois1", "the-number": 3}];
我希望迭代xs
,然后按迭代中的绑定ys
过滤x
。我可以在模板中完全执行此操作吗?像这样的东西?
<div ng-repeat="x in xs">
<h1>{{x}}</h1>
<ul>
<li ng-repeat="y in ys|filter:{y['the-number']:x}">{{y.name}}</li>
</ul>
</div>
编译器说[
是意外的,但这是我知道如何引用不是JavaScript ident字符的字段名的唯一方法。
这是plunkr中的(损坏)代码:
答案 0 :(得分:1)
http://plnkr.co/edit/d3EOFx4XD8tK3WiOZBmq?p=preview
这对我有用:
<div ng-repeat="x in xs">
<h1>{{x}}</h1>
<ul>
<li ng-repeat="y in ys| filter: {'the-number': x}">{{y.name}}</li>
</ul>
</div>