【问题标题】:Autocomplete textbox is not firing selected value自动完成文本框未触发所选值
【发布时间】:2015-09-11 14:43:06
【问题描述】:

我的 AngularJs 应用程序中的自动完成文本框有问题。当我按任意键进行自动完成建议时,我的建议会显示在文本框中,所选值会显示在文本框中。当我尝试在 html 页面上通过 ng-model 显示值时,它只显示我为获取自动完成建议而输入的字符,而不是建议值。

谢谢!!!

这是我的 HTML 代码:

<input type="text" id="tags" data-ng-model="placeselected"  data-ng-keyup="complete()"/>
<br />{{placeselected}}

这是我的 js:

$scope.complete = function() {
    $scope.availablePlaces = [];
    $http({
        method : 'GET',
        url : 'http://localhost:8080/orion-orbit/newclue/cities/ '+  $scope.cityselect.cityCode  + '/clueAnswers'
    }).success(function(data, status, headers,config) {
        $scope.getPlaces=data;
    }).error(function(data, status, headers,config) {
        // called asynchronously if an error occurs
        // or server returns response with an error status.
    });
    angular .forEach($scope.getPlaces,function(value) {
        if (value.getPlaces !=' ') {
            $scope.availablePlaces.push(value.ans);
        }
    });


    $("#tags").autocomplete({
        source : $scope.availablePlaces
    });
}

【问题讨论】:

  • 有没有想过这个问题?

标签: javascript angularjs autocomplete


【解决方案1】:

不要使用$scope 来检索文本框的值,而是使用document.getElementById("id").value

var pickup_location = document.getElementById("pickup_location").value;

希望这会有所帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-11
    • 1970-01-01
    相关资源
    最近更新 更多