我正在尝试过滤服务,但没有过滤从URL获取的数据。 下面是我的代码`
getCustomerList(_archid): void {
this.httpClient.get<ICustomer[]>(this.API_URL)
.subscribe(data => {
this.dataChange.next(data.filter(element => element.cat_type ==_archid));
console.log(data);
},
(error: HttpErrorResponse) => {
console.log (error.name + ' ' + error.message);
});
}
Below is my ICustomer interface
export interface ICustomer {
id:number;
cat_type:string;
CustomerName: string;
}
` _archid是一个字符串,其值为&#34; test&#34;以下是我的json从服务
`
[
{"id":"2","cat_type":"test","CustomerName": "Accenture"},
{"id":"3","cat_type":"security","CustomerName": },
{"id":"4","cat_type":"test","CustomerName": "TCS"},
{"id":"5","cat_type":"test","CustomerName": "CTS"},
{"id":"6","cat_type":"newarch","CustomerName": "WIPRO"},
{"id":"7","cat_type":"colloboration","CustomerName": "Infosys"}
]
`
答案 0 :(得分:0)
我想
Dim regEx As New RegExp
此时数据是ICustomer []的类型吧? 所以数组不包含cat_type吗?
.filter(data=>data.cat_type==_archid)
}
在这一行
getCustomerList(_archid): void {
this.httpClient.get<ICustomer[]>(this.API_URL)
// .filter(data=>data.filter(x=>x.cat_type) ==_archid )
.subscribe(data => {
data.filter(x=>x.cat_type == _archid)
},
(error: HttpErrorResponse) => {
console.log (error.name + ' ' + error.message);
});
x是一种ICustomer,因此它会过滤热数据。
[我对这个棱角分明的东西很新。所以这只是我的研究]