需要帮助才能先加载静态标签并同时点击后端API,以获取建议列表作为自动完成loadTags功能的一部分,因为它仅适用于函数的首次返回能够击中后端并返回列表,否则我能够返回静态列表;
function loadTags(query) {
myLocalTags = _.merge(filteredBasicTags, filteredAdvTags);
apiService.getBackendTags(query).then(function(response) {
myLocalTags = _.values(_.merge(myLocalTags, response.data));
return myLocalTags;
});
//so either I am able to return the apiService Response or the myLocalTags Data for the autocomplete suggestions.
return myLocalTags;
}
您可以做这样的事情:
$scope.autocompleteSuggestions = _.merge(filteredBasicTags, filteredAdvTags);
apiService.getBackendTags(query).then(function(response) {
myLocalTags = _.values(_.merge(myLocalTags, response.data));
$scope.autocompleteSuggestions = myLocalTags;
});