自动填充文本框不会触发选定的值 [英] Autocomplete textbox is not firing selected value

查看:63
本文介绍了自动填充文本框不会触发选定的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的AngularJs应用程序中的自动完成文本框出现问题.当我按任意键进行自动完成建议时,我的建议将显示在文本框中,而选定的值将显示在文本框中.当我尝试通过html页面上的 ng-model 显示值时,它仅显示我键入以获得自动完成建议的字符,而不显示建议值.

I have an issue with my autocomplete textbox in my AngularJs app. When I press any key for autocomplete suggestion, my suggestion is shown in the textbox and the selected value is shown inside the textbox. When I try to show the value by its ng-model on the html page, it only shows the character I typed to get the autocomplete suggestion and not the suggested value.

谢谢!

这是我的HTML代码:

Here is my HTML code:

<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
    });
}

推荐答案

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

Instead of using $scope to retrieve textbox's value, use document.getElementById("id").value

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

希望这会有所帮助!

这篇关于自动填充文本框不会触发选定的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆