[英]need help understanding ngRepeat with filter
I'm trying to figure out what this ng-repeat line of code is doing, 我试图弄清楚这段ng-repeat代码在做什么,
<div ng-repeat="user in filtered = (main.users | candidate: main.filterBy)">
I understand that the line below will simply create a div for all the users in main.users 我知道下面的行会为main.users中的所有用户简单地创建一个div
<div ng-repeat="user in main.users">
What is the first example doing? 第一个示例在做什么? I assume theres some filter going on but it doesn't resemble the syntax of any filter examples I see in the angular docs 我假设有一些过滤器正在进行,但它与我在angular文档中看到的任何过滤器示例的语法都不相似
Basically the above syntax does filtering main.users
by candidate
filter by passing main.filterBy
value to that filter by using this line (main.users | candidate: main.filterBy)
and the result of this is getting stored in filtered
variable. 基本上在上述语法确实滤波main.users
由candidate
通过使过滤器main.filterBy
通过使用此行的值,以该过滤器(main.users | candidate: main.filterBy)
和这样的结果是越来越存储在filtered
变量。 So each time when digest cycle fires up you will see the filtered
value updated. 因此,每次摘要循环启动时,您都会看到filtered
值更新。
Official refactored and semantic syntax is here 官方重构和语义语法在这里
<div ng-repeat="user in main.users | candidate: main.filterBy as filtered">
which clearly says that you can have filtered result in filtered
scope variable which is used as alias of that output. 这清楚地表明您可以在filtered
范围变量中过滤结果,该变量用作该输出的别名。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.