繁体   English   中英

Make Select 框有一个表单输入,可以使用 AngularJS 和 Bootstrap 过滤和搜索我的选项

[英]Make Select box has a form input that can filter and search through my options with AngularJS and Bootstrap

我正在尝试将当前的选择框(当前有很多选项)转换为可搜索的选择框,其中有一个输入,以便于搜索和过滤。

选择框是一个指令,它在应用程序的很多地方都有使用。

我的角度版本:“角度”:“1.3.20”

我的引导程序版本:“angular-bootstrap”:“~0.12.1”

这是我的代码:


.directive('mySelector', function() {
    return {
        template: '<select
                       class="form-control"
                       ng-change="$parent.reloadOtherSelector(inputIdItem, afterList)"
                       ng-model="inputIdItem"
                       ng-options=\'e.id as (e.number + " - " + e.name) for e in $parent.getItems {{angularfilter}}\'
                       ng-required={{objectRequired}}
                       ng-disabled="allowModify == false">
                           <option value="">{{ $parent.labelItem }}</option>
                   </select>',

        restrict: 'E',

        scope : { inputIdItem: '=', inputIdOther: '=', afterList: '=', objectRequired: '=', allowModify: '=', listFilter: '='},

        controller: function($scope){

            $scope.$watch("inputIdItem", function(newValue, oldValue) {
                if (!angular.isUndefined($scope.inputIdOther) && !angular.isUndefined(newValue) && !angular.isUndefined(oldValue))
                    $scope.inputIdOther = null;
            });

            $scope.angularfilter = $scope.listFilter ? (" | filter: " + JSON.stringify($scope.listFilter) + "") : "";
        }
    };
})

我的建议是在您的输入中添加自动完成功能。

这是一个例子 - https://embed.plnkr.co/plunk/CU1K3O

如果您不喜欢使用材料设计,则有一个指令可以让您从 html 端添加和过滤结果。 https://material.angularjs.org/latest/demo/autocomplete

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM