Javascript 如何选择角度视图中对象列表的不同特性值

Javascript 如何选择角度视图中对象列表的不同特性值,javascript,angular,Javascript,Angular,我有以下物品清单: var数据=[ { “AcctId”:100, “价值”:真实 }, { “AcctId”:200, “值”:false } ] 我想像这样选择不同的帐户: 输出:[100200] 我尝试过使用角度过滤器方法: var newData=data.filter(r=>r.AcctId); 但是,它返回与输入相同的列表。有人能告诉我我做错了什么吗?试着这样做: this.result = Array.from(new Set(this.data.map(x => x

我有以下物品清单:

var数据=[
{
“AcctId”:100,
“价值”:真实
},
{
“AcctId”:200,
“值”:false
}
]
我想像这样选择不同的帐户:

输出:[100200]
我尝试过使用角度过滤器方法:

var newData=data.filter(r=>r.AcctId);
但是,它返回与输入相同的列表。有人能告诉我我做错了什么吗?

试着这样做:

this.result = Array.from(new Set(this.data.map(x => x.acctId)));
或者

constructor(){
this.result=this.GetDistinctValues(this.data,“acctId”).map(x=>x.acctId);
}
GetDistinctValues(来源:Array

或lodash方式:

lodash.uniq(this.data.map(x => x.acctId));

您可以使用rxjs库

import { of } from 'rxjs';
import { distinct } from 'rxjs/operators';

interface Person {
age: number,
name: string
}

of<Person>(
    { age: 4, name: 'Foo'},
    { age: 7, name: 'Bar'},
    { age: 5, name: 'Foo'},
).pipe(
    distinct((p: Person) => p.name),
)
.subscribe(x => console.log(x));
从'rxjs'导入{of};
从“rxjs/operators”导入{distinct};
接口人{
年龄:数字,,
名称:string
}
的(
{年龄:4岁,名字:'Foo'},
{年龄:7岁,姓名:'Bar'},
{年龄:5岁,姓名:'Foo'},
).烟斗(
不同((p:Person)=>p.name),
)
.subscribe(x=>console.log(x));
data.map(v=>v.AcctId)
data.filter(r=>r.AcctId)
将只保留任何具有ID值且该值非零的内容。
import { of } from 'rxjs';
import { distinct } from 'rxjs/operators';

interface Person {
age: number,
name: string
}

of<Person>(
    { age: 4, name: 'Foo'},
    { age: 7, name: 'Bar'},
    { age: 5, name: 'Foo'},
).pipe(
    distinct((p: Person) => p.name),
)
.subscribe(x => console.log(x));