我对angular还是很陌生,所以我想知道如何最好地做这样的事情:


我有一个json文件,该文件返回各种类型为“ course”和“ tutorial”的项目。教程与具有相关领域的课程有关

data = [ { title: foo1, type: course, id:1}, { title: foo2, type: course, id:2}, { title: foo3, type: course, id:3}, { title: t1, type: tutorial, id:4, related_course:2}, { title: t2, type: tutorial, id:5, related_course:2}, { title: t3, type: tutorial, id:6, related_course:3}, ...


在我的控制器中,我具有绑定到$scope的函数,以允许我按类型进行过滤。

现在在我的模板中

<div ng-repeat="item in data | filter:isCourse">
... display course data
   <div ng-repeat="item in data | filter.isTutorial">
   ... display tutorial data


我想找到一种方法来确保显示的教程与当前显示的课程的ID匹配。

有什么建议么?

谢谢!
-V

最佳答案

然后,您应该特定于filters,但请确保JSON的格式正确,因为我可以看到大多数值都不在"中包装(双引号)

的HTML

<div ng-repeat="course in data | filter: {type: 'course'}">
... display course data
   <div ng-repeat="tut in data | filter: { related_course: course.id }">
   ... display tutorial data


Working Fiddle(感谢@AWolf)

关于javascript - Angular 过滤器相关数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36072305/

10-09 17:57
查看更多