【问题标题】:Angular JS and jQuery UI autocomplete featureAngular JS 和 jQuery UI 自动完成功能
【发布时间】:2015-03-31 07:47:28
【问题描述】:

我正在尝试使用纯角度构建自动完成功能,但不幸的是 UI 有点难以处理。我开始使用 jQuery UI 构建它。

然后我遇到了一个小提琴 http://jsfiddle.net/sebmade/swfjT/light/

<div ng-app='MyModule'>
    <div ng-controller='DefaultCtrl'>
        <input auto-complete ui-items="names" ng-model="selected">
        selected = {{selected}}
    </div>
</div>



function DefaultCtrl($scope) {
    $scope.names = ["john", "bill", "charlie", "robert", "alban", "oscar", "marie", "celine", "brad", "drew", "rebecca", "michel", "francis", "jean", "paul", "pierre", "nicolas", "alfred", "gerard", "louis", "albert", "edouard", "benoit", "guillaume", "nicolas", "joseph"];
}

angular.module('MyModule', []).directive('autoComplete', function($timeout) {
    return function(scope, iElement, iAttrs) {
            iElement.autocomplete({
                source: scope[iAttrs.uiItems],
                select: function() {
                    $timeout(function() {
                      iElement.trigger('input');
                    }, 0);
                }
            });
    };
});

我只想在用户输入 3 个有效字符后显示选项。

谢谢, 安吉坦纳

【问题讨论】:

    标签: javascript jquery angularjs jquery-ui autocomplete


    【解决方案1】:

    您可以使用minLength 选项:

    iElement.autocomplete({
        source: scope[iAttrs.uiItems],
        minLength: 3,
        select: function() {
            $timeout(function() {
              iElement.trigger('input');
            }, 0);
        }
    });
    

    【讨论】:

    • 嗨,非常感谢。这行得通。 :) 我不知道这些选项。
    • 这是正确的解决方案:)
    猜你喜欢
    • 2018-08-17
    • 1970-01-01
    • 1970-01-01
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-16
    • 1970-01-01
    相关资源
    最近更新 更多