【问题标题】:ui-select-choices object (hashtable) instead of array of objectsui-select-choices 对象(哈希表)而不是对象数组
【发布时间】:2016-01-14 08:34:06
【问题描述】:

我有以下ui-select 工作:

<ui-select ng-model="vm.example" name="example">
    <ui-select-match placeholder="Select...">{{$select.selected.key}}</ui-select-match>
        <ui-select-choices repeat="x in vm.examples | filter: $select.search">
            <div ng-bind-html="x.key | highlight: $select.search"></div>
    </ui-select-choices>
</ui-select>

而这个选择的来源是下面的数组...

vm.examples = [
    {key:'a', value: 1},
    {key:'b', value: 2},
    {key:'c', value: 3}
]

但是,我希望我的“数据源”选择是一个对象文字,如下所示......

vm.examples = {
    a: 1,
    b: 2,
    c: 3
}

我已经尝试了几次,但无法使其工作,有什么想法吗?如果由于ui-select 当前实现而无法实现...有人知道原因吗??

提前致谢!

【问题讨论】:

    标签: angularjs hashtable ui-select angular-ui-select


    【解决方案1】:

    我终于在ui-select wiki GitHub 上找到了答案!

    <ui-select ng-model="person.selectedValue" title="Choose a person">
      <ui-select-match placeholder="Select a person in the list or search his name/age...">{{$select.selected.value.name}}</ui-select-match>
      <ui-select-choices repeat="person.value as (key, person) in peopleObj | filter: {'value':$select.search}">
        <div ng-bind-html="person.value.name | highlight: $select.search"></div>
        <small>
          email: {{person.value.email}}
          age: <span ng-bind-html="''+person.value.age | highlight: $select.search"></span>
        </small>
      </ui-select-choices>
    </ui-select>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-01-28
      • 2010-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-21
      • 1970-01-01
      相关资源
      最近更新 更多