动态地改变滤波器前pression [英] dynamically change the filter expression
问题描述
我有一个记录数组。此阵列将显示基于用户的权限不同的记录。
I have an array of records. This array will display different records based on the user's permissions.
因此,我不得不使用基于用户不同的过滤器。如何创建这样一个前pression这需要根据用户的权限的可变功能 -
Thus I have to use a different filter based upon the user. How do i create such an expression which takes a variable function based on the user's permission -
<div ng-repeat="r in records | filter:{isVisible:true}"
上面有一个过滤器前$ P $ {pssion可见性:真实}。我想,动态地分配根据用户不同的过滤器的前pression。因此,用户2将有{isCommon:M2}。
The above has a filter expression {isVisible:true}. I want to dynamically assign a different filter expression based on the user. So user2 will have {isCommon: 'M2'}.
推荐答案
过滤前pressions可变数太多:
Filter expressions can be variables too:
<li ng-repeat="item in items | filter:filterExpr">{{item.name}}</li>
凡恩pression是在范围定义的:
Where the expression is defined on the scope:
$scope.filterExpr = { tester: true };
下面的这个更全面展示了Plunker: http://plnkr.co/edit/Au8KFg?p = preVIEW
Here's a Plunker that demonstrates this more completely: http://plnkr.co/edit/Au8KFg?p=preview
PS:请留意@ MarkRajcok的评论您的帖子,因为它的非常需要注意的
PS: Do pay heed to @MarkRajcok's comment to your post as it is very important to note.
这篇关于动态地改变滤波器前pression的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!