2017-04-03 70 views
0

我使用的是angularjs ui-select, ,正如我在默認情況下在綁定中理解的那樣,我需要的是一個數組的多重下拉列表,問題是我需要具有相同的行爲單選也是。angularjs ui-select綁定到一個數組

$scope.mdf.options = [{ id: 1, name: 'name1' },{ id: 2, name: 'name2' }]; 

<ui-select ng-model="wrap.piece.original.selections_hash[mdf.id]" close-on-select="false" title="mdf.modifier.display" ng-if="mdf.modifier.max == 1"> 
    <ui-select-match>{{$select.selected.name}}</ui-select-match> 
     <ui-select-choices repeat="option.id as option in mdf.options"> 
      <span ng-bind="option.name"> 
      </span> 
     </ui-select-choices> 
</ui-select> 

因此,當用戶例如選擇NAME2我需要我的模型更新爲[2]而不是2 我怎樣才能做到這一點?我可以使用ui-select嗎?如果不是,我可以用角度選擇來做到嗎?

回答

0

我認爲你正在尋找一個關鍵的屬性綁定。 也許這會幫助你。 "Example key binding"

下面是從plunker代碼(從示例站點):

<ui-select ng-model="ctrl.person.selectedSingleKey" theme="select2" ng-disabled="ctrl.disabled" style="min-width: 300px;" 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.key as (key, person) in ctrl.peopleObj | filter: { value: { name: $select.search }}"> 
    <div ng-bind-html="person.value.name | highlight: $select.search"></div> 
    <small> 
    email: {{person.value.email}} 
    age: {{person.value.age}} 
    </small> 
</ui-select-choices> 

相關問題