【问题标题】:How to set max length for ui-select-match如何设置 ui-select-match 的最大长度
【发布时间】:2017-01-23 13:34:21
【问题描述】:

我正在使用“ui-select-macth”来添加多个值。有什么办法可以设置每次输入的文本字段的最大长度,如果可以,你能帮帮我吗?

【问题讨论】:

    标签: angularjs


    【解决方案1】:

    好的,有你的问题。

    以下是 HTML 代码:

    <div ng-app="ngrepeatSelect" ng-controller="ExampleController">
      <form name="myForm">
        <label for="repeatSelect"> Repeat select: </label>
        <select name="repeatSelect" id="repeatSelect" ng-model="data.repeatSelect">
          <option ng-repeat="option in data.availableOptions" value="{{option.id}}">{{option.name | truncate:3 }}</option>
        </select>
      </form>
      <hr>
      <tt>repeatSelect = {{data.repeatSelect}}</tt><br/>
    </div>
    

    以下是 Angular js 代码。我使用了 ui-select 匹配和选项以及 ng-repeat 以及过滤器。

    angular.module('ngrepeatSelect', [])
     .controller('ExampleController', ['$scope', function($scope) {
       $scope.data = {
        repeatSelect: null,
        availableOptions: [
          {id: '1', name: 'Option A'},
          {id: '2', name: 'Option B'},
          {id: '3', name: 'Option C'}
        ],
       };
    
    }])
    .filter('truncate', function () {
            return function (text, length, end) {
                if (isNaN(length))
                    length = 10;
    
                if (end === undefined)
                    end = "";
    
                if (text.length <= length || text.length - end.length <= length) {
                    return text;
                }
                else {
                    return String(text).substring(0, length-end.length) + end;
                }
    
            };
        });
    

    Click here 去上面的代码演示。

    【讨论】:

    • 感谢您的回复。但它描述了我们可以限制的选择数量。但我的问题是如何限制我们在占位符上输入的文本
    猜你喜欢
    • 2017-08-05
    • 1970-01-01
    • 2018-08-31
    • 2015-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-01
    • 2012-09-27
    相关资源
    最近更新 更多