【问题标题】:AngularJS UI-Select as ComboBoxAngularJS UI-选择为组合框
【发布时间】:2016-08-12 09:51:23
【问题描述】:

我正在使用 ui-select(version 0.18.1) 插件(在单选模式

参考:https://github.com/angular-ui/ui-select

我非常喜欢 UI 和功能,因为我们可以从绑定到该控件的选项列表中搜索我们需要的选项。

现在我的需要是我需要这个 UI-Select 控件作为 ComboBox 工作,即如果在项目列表中找不到搜索的项目,那么在按下“ENTER”键时,项目应该添加到我们的基本项目列表中,它应该默认选中。

我在单选模式下需要这个,我已经在谷歌上搜索过这个但我能找到的只是 UI-Select 多模式和标签。

我不需要 UI-Select 中的标签,我需要它作为选项列表中的选项。

【问题讨论】:

    标签: javascript jquery angularjs combobox angular-ui-select


    【解决方案1】:

    我找到了解决办法,

    issue 已经在 github 的 ui-select 库中提出。

    这是一个错误 - 使用 angularjs 1.3.2 时,没有多个新标签的标签不起作用,但它已经解决了,如果你下载最新的 ui-select 库,很可能已经解决了这个问题。

    您也可以访问this 一个。

    tagging-label="false"
    

    这个可能对你有用。

    【讨论】:

    • 您好,感谢您的回复,我试过了。但无法让它工作。您能否提供一个示例 plunker 或类似的东西,我正在使用 angular 版本 v1.5.0 和 ui-select 版本 0.18.1
    • 您好,我已经使用最新的 ui-select 版本 0.19.1 再次尝试过,并且部分工作正常。但它没有清除 $select.clear(); 上的选择;它也将项目显示为标签,但我需要将其显示为列表中的项目。在标记模式下删除选择时,占位符不显示 -None-
    • 好的@PavanKosanam,你可以在它的图书馆的问题中找到它,有很多问题被提出......我不太清楚。
    【解决方案2】:

    我写了额外的指令 ui-combobox 并添加了一些配置

    <ui-select 
      ng-model="ctrl.person.selected" theme="select2" 
      reset-search-input='false'
      ui-combobox="email"
     style="min-width: 300px" >
        <ui-select-match placeholder="...">
          {{ctrl.person.selected}}
          </ui-select-match>
        <ui-select-choices repeat="person.email as person in ctrl.people | propsFilter: {name: $select.search, age: $select.search}">
          <div ng-bind-html="person.name | highlight: $select.search"></div>
        </ui-select-choices>
      </ui-select>
    
    
    
        app.directive('uiCombobox', function() {
              return {
                require: 'uiSelect',
                link: function(s, e, a, uiSelect) {
                  s.$watch(function() {
                    return uiSelect.search
                  },function() {
                    if(!uiSelect.search) return;
                    console.log(uiSelect.search);
                    var obj = {};
                    obj[a.uiSel] = uiSelect.search;
                    s.$broadcast('uis:select', obj);
                  });
                }
              }
    
            })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-19
      • 1970-01-01
      • 1970-01-01
      • 2016-05-05
      相关资源
      最近更新 更多