【问题标题】:AngularJS uib-typeahead not updating list of valuesAngularJS uib-typeahead 不更新值列表
【发布时间】:2018-06-04 17:37:10
【问题描述】:

我有以下 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 调用对其进行更新,这是我在控制器中使用它的方式(取自 this question):

$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 区域登录它时,它显示了我的所有值期待它坚持下去。

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

EDIT 添加我定义 Angular 服务的工厂:

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

【问题讨论】:

    标签: javascript angularjs asynchronous angular-ui-bootstrap


    【解决方案1】:

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

    你的意思是location as location.country.name?弄错了会导致空白列表。

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-18
      相关资源
      最近更新 更多