我使用md-autocomplete讓用戶在我的大學中搜索主題。AngularJS md-autocomplete返回所有可能的子字符串
問題是我的搜索功能,通過每個顯示值只搜索(從左到右)。
例如:如果我搜索「藝術與建築」,我會得到「找不到結果」,我不希望發生這種情況。
我想要「藝術與建築學」返回結果。
的對象是格式爲:
$scope.subjects = [
{
value: 'AA',
display: 'AA - Arts and Architecture'
},
{
value: 'AAAS',
display: 'AAAS - African/Afr Amer Studies'
},
{
value: 'ABA',
display: 'ABA - Applied Behavior Analysis'
},
{
value: 'ABE',
display: 'ABE - Ag and Biological Engineering'
}
]
這裏是我的搜索方法:
$scope.searchQuery = function(text) {
text = text.toUpperCase();
var result = $scope.subjects.filter(function(item) {
return item.display.includes(text);
});
return result;
}
這裏是我的html:
<md-autocomplete
md-selected-item="selectedItem"
md-search-text="searchText"
md-items="item in searchQuery(searchText)"
md-item-text="item.display"
md-min-length="0"
placeholder="Select a subject">
<md-item-template>
<span md-highlight-text="searchText">{{item.display}}</span>
</md-item-template>
<md-not-found>
No matches found.
</md-not-found>
</md-autocomplete>
希望我能接受這兩次 - 謝謝! – User11
沒問題,你總是可以upvote反而!高興它幫助。 –
沒有足夠的代表 – User11