多烫发AngularJS过滤器 [英] AngularJS filter with multiple perms
问题描述
我有一个用户这样
[{id:1,name:'name',parent_id:0,type:1},
{id:2,name:'name2',parent_id:0,type:2},
{id:3,name:"name1 child",parent_id:1,type:1}]
和我试图根据PARENT_ID和类型ID显示家长和儿童用户,以便例如ID 3 ID 1的孩子,我是想这样显示这些
and i am trying to display parents and child users based on parent_id and type id so for example id 3 is child of id 1 and i am trying to display them like this
http://jsfiddle.net/U3pVM/689/
感谢您的帮助。
推荐答案
我搞掂你的提琴:
<div ng-controller="MyCtrl">
<ol>
<li ng-repeat="user in users | filter:{parent_id:0}">
{{user.name}}
<ol>
<li ng-repeat="child in users | filter:{parent_id:user.id, type:user.type}">
{{child.name}}
</li>
</ol>
</li>
</ol>
</div>
您的主要问题是,你试图用过滤器过滤器功能,这是好的,但该功能是不允许带任何参数。如果你确实需要创建一个过滤器,需要的参数,你必须编写自定义过滤器: http://docs.angularjs.org/guide/dev_guide.templates.filters.creating_filters 。
Your main problem was that you were trying to use the "filter" filter with a function, which is okay, but that function isn't allowed to take any parameters. If you actually need to create a filter that takes parameters you have to write a custom filter: http://docs.angularjs.org/guide/dev_guide.templates.filters.creating_filters.
但在你的情况,你可以使用标准的过滤器过滤器和它传递的对象,会做你想做的。
But in your case, you can use the standard "filter" filter and pass it objects that will do what you want.
另外,你骂开发商角创建一个抽象称为过滤器,然后创建一个过滤器过滤器。我的意思是,如何混乱?
Also, curse you Angular developers for creating an abstraction called filter and then creating a "filter" filter. I mean, how confusing is that?
这篇关于多烫发AngularJS过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!