【发布时间】:2016-02-28 23:11:18
【问题描述】:
我有一组这样的数据
$scope.students = [
{ name:"John", courses:["Math", "Physics", "Chemistry"] },
{ name:"Paul", courses:["Economics", "Math", "Sociology"] }
]
我想要一种使用角度过滤器进行过滤的方法,这样我就可以获得所有主题的列表而无需重复。 我一直在尝试使用独特的过滤器,但我无法让它工作,因为我尝试像这样进行迭代
<ul ng-repeat="student in students">
<li ng-repeat="x in student.courses | unique:courses"></li>
{{x}}
</ul>
我想要的第一个 ng-repeat 的输出是这样的数组:
["Math", "Physics", "Chemistry", "Economics", "Sociology"]
所以我可以在第二个中遍历它。
我通过仅使用所需数组创建一个新范围来实现这一点,但是我无法正确绑定它,所以我想通过过滤来实现它。提前致谢。
【问题讨论】:
-
您可以使用该库:github.com/angular-ui/angular-ui/blob/master/modules/filters/…。顺便说一句,
ng-repeat必须专门用于<li>标签而不是<ul>。 -
@Martin,情况不同,因为我是独一无二的:如果课程引用数组,则课程不起作用
-
@developer033,是的,这正是我想要使用的,但我不知道如何实现:)
标签: angularjs angularjs-ng-repeat angularjs-filter