2017-04-03 32 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> 

相关问题