简体   繁体   English

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

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

I'm trying to turn a current select box (which currently have a lot of options) to a searchable select box, with a input inside it to make search and filtering easier.我正在尝试将当前的选择框(当前有很多选项)转换为可搜索的选择框,其中有一个输入,以便于搜索和过滤。

The select box is a directive, and it's used in many places on the application.选择框是一个指令,它在应用程序的很多地方都有使用。

My angular version: "angular": "1.3.20"我的角度版本:“角度”:“1.3.20”

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

Here's my code:这是我的代码:


.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) + "") : "";
        }
    };
})

My suggestion would be to add an autocomplete to your input.我的建议是在您的输入中添加自动完成功能。

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

If you not apposed to using material design there is a directive that you and add and filter your results from your html side.如果您不喜欢使用材料设计,则有一个指令可以让您从 html 端添加和过滤结果。 https://material.angularjs.org/latest/demo/autocomplete https://material.angularjs.org/latest/demo/autocomplete

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

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