ng-Model="something.$" 什么意思?
Ng-Model="something.$" what does this mean?
我是 Angular 的新手,我在阅读过滤器文档时看到了这段代码。
<label>Any: <input ng-model="search.$"></label> <br>
<label>Name only <input ng-model="search.name"></label><br>
<label>Phone only <input ng-model="search.phone"></label><br>
<tr ng-repeat="friendObj in friends | filter:search:strict">
我不清楚 ng-model="search.$"
是什么意思。 ng-model
的两种绑定方式很清楚,但是 "search.$"
呢?那是做什么的,它是如何与过滤器一起工作的。
我尝试搜索此内容,但找不到任何内容。谢谢!
它特定于过滤器逻辑。 $
用作 属性 匹配器来匹配列表中对象的所有属性的值。因此,在您的过滤器中,绑定表达式是对象 search
并将匹配器字符串指定为 $
属性 (这是搜索输入的 ng-model) search
将使过滤器能够比较 friendObj
的所有属性的值以进行匹配。
Note that a named property will match properties on the same level only, while the special $ property will match properties on the same level or deeper. E.g. an array item like {name: {first: 'John', last: 'Doe'}} will not be matched by {name: 'John'}, but will be matched by {$: 'John'}.
在您复制的示例正上方的文档中对此进行了解释:
A special property name $ can be used (as in {$:"text"}) to accept a match against any property of the object or its nested object properties.
因此,通过将文本框绑定到 search.$
,该示例启用了对所有可用属性的搜索。
我是 Angular 的新手,我在阅读过滤器文档时看到了这段代码。
<label>Any: <input ng-model="search.$"></label> <br>
<label>Name only <input ng-model="search.name"></label><br>
<label>Phone only <input ng-model="search.phone"></label><br>
<tr ng-repeat="friendObj in friends | filter:search:strict">
我不清楚 ng-model="search.$"
是什么意思。 ng-model
的两种绑定方式很清楚,但是 "search.$"
呢?那是做什么的,它是如何与过滤器一起工作的。
我尝试搜索此内容,但找不到任何内容。谢谢!
它特定于过滤器逻辑。 $
用作 属性 匹配器来匹配列表中对象的所有属性的值。因此,在您的过滤器中,绑定表达式是对象 search
并将匹配器字符串指定为 $
属性 (这是搜索输入的 ng-model) search
将使过滤器能够比较 friendObj
的所有属性的值以进行匹配。
Note that a named property will match properties on the same level only, while the special $ property will match properties on the same level or deeper. E.g. an array item like {name: {first: 'John', last: 'Doe'}} will not be matched by {name: 'John'}, but will be matched by {$: 'John'}.
在您复制的示例正上方的文档中对此进行了解释:
A special property name $ can be used (as in {$:"text"}) to accept a match against any property of the object or its nested object properties.
因此,通过将文本框绑定到 search.$
,该示例启用了对所有可用属性的搜索。