【问题标题】:UI-Select case InsensitiveUI-选择不区分大小写
【发布时间】:2016-10-03 18:30:33
【问题描述】:

有什么方法可以忽略 ng-model 和 select item 之间的大小写?

我遇到的这个问题是 log.username 是一个输入框,而不是一个下拉列表,所以旧的用户名都有不同的大小写。

例子:

log.username = "doej";

lookupOptions.users = [{username:"DoeJ", fullName:"Joe Doe"}, {用户名:“SmithM”,全名:“MarySmith”}]

加载时选择为空而不是“DoeJ”

 <div class="form-group col-md-4">
        <label>Stored By</label>
        <ui-select ng-model="log.username" theme="bootstrap">
            <ui-select-match placeholder="Select Site">{{$select.selected.username}}</ui-select-match>
            <ui-select-choices repeat="option.username as option in lookupOptions.users | orderBy: 'username' | propsFilter: {'username':  $select.search}">
                <div ng-bind-html="option.username | highlight: $select.search"></div>
                <small ng-bind-html="option.fullName | highlight: $select.search"></small>
            </ui-select-choices>
        </ui-select>
    </div>

【问题讨论】:

  • 使用 ng-repeat="option 作为 lookupOptions.users 中的选项",它有效吗?
  • 不幸的是 ng-model 寻找确切的字符串值。所以,选择将是空的,否则log.username = 'DoeJ'

标签: angularjs angular-ui-select


【解决方案1】:

这就是我所做的:

控制器:

log.username = log.username ? log.username.toLowerCase() : ""; 

查看:

    <div class="form-group col-md-4">
        <label>Stored By</label>
        <ui-select ng-model="log.username" theme="bootstrap">
            <ui-select-match placeholder="Select Site">{{$select.selected.username}}</ui-select-match>
            <ui-select-choices repeat="option.username.toLowerCase() as option in lookupOptions.users | orderBy: 'username' | propsFilter: {'username':  $select.search}">
                <div ng-bind-html="option.username | highlight: $select.search"></div>
                <small ng-bind-html="option.fullName | highlight: $select.search"></small>
            </ui-select-choices>
        </ui-select>
    </div>

【讨论】:

    猜你喜欢
    • 2014-05-24
    • 2011-05-16
    • 1970-01-01
    • 2014-05-22
    • 2015-11-10
    • 1970-01-01
    • 2021-10-19
    • 2011-11-25
    • 2021-08-27
    相关资源
    最近更新 更多