AngularJS 过滤器:Return 对象数组与预期字符串不匹配
AngularJS Filter: Return array of objects not matching expected string
在AngularJS中,'filter' filter可以查看一个对象数组,return只有那些具有包含字符串比较器的字符串属性值的数组.
因此,下面将给出对象数组 people
的每个成员的列表,其中任何 属性 如 surname: 'Smith'
或 occupation: '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>
在AngularJS中,'filter' filter可以查看一个对象数组,return只有那些具有包含字符串比较器的字符串属性值的数组.
因此,下面将给出对象数组 people
的每个成员的列表,其中任何 属性 如 surname: 'Smith'
或 occupation: '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>