2016-01-14 48 views
1

我有以下ui-select工作的數組:UI的選擇,選擇的對象(哈希表),而不是對象

<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 
} 

我已經嘗試了好幾次,無法讓它工作,有什麼想法?如果由於當前的實現而無法實現...有人知道原因?

在此先感謝!

回答

0

我終於在 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>