我试图使用两个过滤器方法基于字符串过滤对象内的数组。这是我的对象的样子。
[
{
"cat": "Accommodation and Food Service Activities",
"value": [
{
"sic": "55",
"desc": "Accommodation"
},
{
"sic": "56",
"desc": "Food and beverage service activities"
}
]
},
{
"cat": "Activities Of Extraterritorial Organisations and Bodies",
"value": [
{
"sic": "99",
"desc": "Activities of extraterritorial organisations and bodies"
}
]
}
]
我正在尝试过滤value.desc
并返回cat
这是我到目前为止所拥有的
filteredIndustries(industry: string) {
if (industry) {
return this.industries.filter(sector => {
if (sector.value) {
sector.value.findIndex( v => {
return v.desc.toString().toLowerCase().indexOf(industry.toString().toLowerCase()) === 0;
});
}
});
} else {
return this.industries;
}
这是我的HTML,
<md-input-container>
<input mdInput placeholder="Industry" [mdAutocomplete]="auto" [formControl]="industryCtrl">
</md-input-container>
<md-autocomplete #auto="mdAutocomplete" [displayWith]="displayIndustry.bind(this)">
<md-option *ngFor="let industry of filteredIndustry | async" [value]="industry">
{{ industry.cat }}
</md-option>
</md-autocomplete>
因此,当我输入食物时,应该在value.desc
上过滤并返回cat
Accommodation and Food Service Activities
但即使我的返回结果为真,我也没有得到任何返回值。
非常感谢任何帮助。