在 AngularJS 中,'filter' filter可以查看对象数组并仅返回具有包含字符串比较器的字符串属性值的数组。
因此,以下内容将给出对象数组 people
中每个成员的列表,其中包含任何属性,如 surname: 'Smith'
或 ocupation: 'Blacksmith '
或 address_1: '123 Smithfield Lane'
等。
<ul>
<li ng-repeat="person in people | filter: 'Smith'">
{{ person.name }}
</li>
</ul>
使用 AngularJS 获取仅包含不包含字符串'Smith'
的对象的数组的最佳方法是什么?
最佳答案
来自https://docs.angularjs.org/api/ng/filter/filter
The predicate to be used for selecting items from array.
Can be one of:
string: The string is used for matching against the contents of the array. All strings or objects with string properties in array that match this string will be returned. This also applies to nested object properties. The predicate can be negated by prefixing the string with !
<li ng-repeat="person in people | filter: '!Smith'">
{{ person.name }}
</li>
如果您想按名称过滤,则仅使用对象谓词
<li ng-repeat="person in people | filter: { name : '!Smith'}">
{{ person.name }}
</li>
关于javascript - AngularJS过滤器: Return array of objects not matching expected string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32285172/