[英]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.