[英]AngularJS uib-typeahead not updating list of values
我有以下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);}
我首先尝试将所有逻辑都放在一种相同的方法中,但没有区别,即使我在.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
吗? 弄错了将导致空白列表。
如果您可以将位置数据样本添加到您的问题中,那将有助于发现问题所在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.