【发布时间】:2018-01-03 15:06:19
【问题描述】:
您好,我有一个 md 自动完成搜索框,我的问题是在输入名称时会调用搜索功能。搜索函数调用一个 api,但同时它返回一个空数组到自动完成表单。有没有办法告诉函数不返回任何内容并在找到某些内容后返回答案?另外,在我们等待这些结果时,让 md 自动完成显示加载文本或图像?请在下面找到代码:
代码: html -
<md-autocomplete md-selected-item="selectedLocation" md-selected-item-change="selectLocation(item)" md-search-text="searchText"
md-items="item in searchLocations(searchText)" md-item-text="item.Name" md-min-length="3" placeholder="search location" md-select-on-match="true"
md-match-case-insensitive="true" md-no-cache="true">
<md-item-template>
<span md-highlight-text="searchText">{{item.id}}</span>
</md-item-template>
<md-not-found>
No results found.
</md-not-found>
</md-autocomplete>
JS-
$scope.searchLocations = function(txt) {
console.log("Searching locations in " + txt);
if (!isNaN(txt) && txt.length == 6) {
params = {locationIds: [txt]};
}
locations = Location.query(params);
console.log("locations found:" + locations.length); //this return 0 every time
return locations;
}
【问题讨论】:
标签: javascript html md-autocomplete