我不确定我做错了什么还是在ngx管道中发现错误。 因此,假设我要按ID = 1进行过滤。我实际上正在获取ID 1、11和14。
我正在使用文档中的示例,我刚刚添加了2个新对象:
users = [
{id: 1, first_name: 'John', last_name: 'Doe', work: { company: 'Foo Tech' }},
{id: 2, first_name: 'Jane', last_name: 'West', work: { company: 'AAA Solutions' }},
{id: 3, first_name: 'Bruce', last_name: 'John', work: { company: 'Bar Tech' }},
{id: 4, first_name: 'William', last_name: 'Cent', work: { company: 'Foo Tech' }, arr: [{name: 'foo'}]},
{id: 11, first_name: 'William', last_name: 'Cent', work: { company: 'Foo Tech' }, arr: [{name: 'foo'}]},
{id: 14, first_name: 'William', last_name: 'Cent', work: { company: 'Foo Tech' }, arr: [{name: 'foo'}]}]
<div *ngFor="let user of users | filterBy: ['id']: 1">
{{user | json}}
</div>
结果:
{“ id”:1,“ first_name”:“ John”,“ last_name”:“ Doe”,“ work”:{“ company”:“ Foo Tech”}} {“ id”:11,“ first_name”:“ William”,“ last_name”:“ Cent”,“ work”:{“ company”:“ Foo Tech”},“ arr”:[{“ name”:“ foo “}]} {“ id”:14,“ first_name”:“ William”,“ last_name”:“ Cent”,“ work”:{“ company”:“ Foo Tech”},“ arr”:[{“ name”:“ foo “}]}
答案 0 :(得分:1)
尝试这种方式>
<div *ngFor="let user of users | filterBy: ['id']: 1: true">
{{user | json}}
</div>
您需要将strict设置为true