我想基於使用兩種過濾方法的字符串過濾對象內的數組。這是我的對象的樣子。使用自動完成功能在對象內過濾數組
[
{
"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 –