AngularJS uib-typeahead 不更新值列表



我有以下uib-typeahead标记:

<input type="text" class="form-control" id="field_location" ng-model="surveyData.location"
placeholder="Search"
uib-typeahead="location as location.name for location in newListLocations | filter:$viewValue:customSearch | orderBy:location.country.name | limitTo:200"
typeahead-editable="false">

我用一个在后端完美运行的 REST 调用更新它,这是我在控制器中使用它的方式(取自这个问题(:

$scope.filterLocations = function(searchValue, viewValue) {
var newListOfLocations = LocationTypeaheadFilter.queryWithTypeaheadSearchValue(viewValue).then(function (list){
$scope.newListLocations = list.data;
console.log($scope.newListLocations);
return $scope.newListLocations;
},
function errorCallback(response) {
alert('Error');
throw response;
});
return newListOfLocations;
};

使用此标记中的原始函数调用此函数:

$scope.customSearch = function(searchValue, viewValue){
return $scope.filterLocations(searchValue, viewValue);}

我首先尝试将所有逻辑放在一个相同的方法中,但没有区别,typeahead 的列表总是显示为空,即使当我将其记录在控制台的.then区域时,它会显示我希望它包含的所有值。

我已经尝试了许多不同的方法,但我相信它应该按照我编码的方式工作,前提是我正在等待回调

编辑以添加我定义 Angular 服务的工厂:

.factory('LocationTypeaheadFilter', function ($http, DateUtils) {
return {
queryWithTypeaheadSearchValue: function(query){
return $http.get("api/locationssearchTypeahead/"+query)
}
}});

我注意到你正在使用location as location.name,然后稍后在你使用的相同表达式中orderBy:location.country.name.location.name是有效的路径吗?

你是说location as location.country.name吗?弄错了会导致空白列表。

如果您可以在问题中添加位置数据的示例,这将有助于找出问题所在。

最新更新