我想基于使用两种过滤方法的字符串过滤对象内的数组。这是我的对象的样子。使用自动完成功能在对象内过滤数组
[
{
"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
但我没有得到,即使我的返回结果为true的返回值。
任何帮助将不胜感激。
欢迎SO!这是一个很好的第一个问题,您发布了代码并正确解释了您的问题,使您可以轻松地为您提供帮助。 +1 –