【问题标题】:Angular ui-select array of objects - first item not selectable角度 ui-select 对象数组 - 第一项不可选择
【发布时间】:2015-02-03 07:40:38
【问题描述】:

情况:

在我的应用程序中,我使用 angular ui-select 显示人员列表(对象数组)。

除了一个小问题,一切正常:

列表的第一项不可选择。我不能选择它。


代码:

<ui-select multiple tagging tagging-label="new tag" ng-model="multipleDemo.selectedPeople" theme="select2" ng-disabled="disabled" style="width: 800px;">
  <ui-select-match placeholder="Select person...">{{$item.name}} &lt;{{$item.email}}&gt;</ui-select-match>
  <ui-select-choices repeat="person in people | propsFilter: {name: $select.search, age: $select.search}">
    <div ng-bind-html="person.name | highlight: $select.search"></div>
    <small>
      email: {{person.email}}
      age: <span ng-bind-html="''+person.age | highlight: $select.search"></span>
    </small>
  </ui-select-choices>
</ui-select>


PLUNKER:

http://plnkr.co/edit/CVaMvt4zBUBD2QEsfIdk?p=preview


问题:

如何选择 angular ui-select - 对象数组中的第一项?


注意:

Alexander 的答案是正确的,因为为 ui-select 哪个版本

从 0.9.5 版开始。此问题已解决。

这是在 GitHub 中打开的问题:

https://github.com/angular-ui/ui-select/issues/477#issuecomment-66795541

【问题讨论】:

    标签: javascript arrays angularjs select ui-select


    【解决方案1】:

    修复 v0.9.4.

    调试 10 分钟后,我发现这一行有错误 (ui-select source code)

    item = ctrl.tagging.fct !== undefined 
             ? ctrl.tagging.fct(ctrl.search) 
             : item.replace(ctrl.taggingLabel,'');
    

    item 是对象而不是字符串,这就是发生错误的原因。如果您将此 tagging-label="" 选项设置为 false,您将可以选择第一项。我不知道什么时候 item 将作为字符串传递,也许这是错误,或者需要设置其他选项来实现这一点..

    【讨论】:

      【解决方案2】:

      事实证明,在 v0.9.4 及更早版本中存在导致此问题的标记功能的错误。最好的解决方法是将ui-select 更新到版本 0.9.5+。

      附带说明,您的示例缺少必需的 tagging $scope 函数,请阅读插件文档:https://github.com/angular-ui/ui-select/wiki/ui-select

      tagging - 启用标记模式(动态添加新项目)。接受作为范围函数的字符串。如果您的模型是对象数组,则此字符串是必需的。该函数会将新项目作为字符串传递,并应返回一个对象,该对象是要推送到项目数组的转换值

      如果您正在处理对象数组,您必须定义一个标记函数,以便指令知道您希望将要推送到数组的对象应该是什么样子。

      【讨论】:

        猜你喜欢
        • 2015-02-01
        • 1970-01-01
        • 1970-01-01
        • 2017-12-26
        • 1970-01-01
        • 2021-03-03
        • 1970-01-01
        • 1970-01-01
        • 2017-07-15
        相关资源
        最近更新 更多