Angularjs ui-select:如何为多个下拉菜单设置选定的值

时间:2016-05-29 18:19:32

标签: angularjs angular-ui-select

我在页面上有多个ui-selection。如何单独为每个项目设置选定的值,从而使用从服务中检索的单个列表?

HTML:

<div class="col-sm-4">
   <ui-select class="col-sm-12 no-padding" ng-model="mappingStrengthList.selected">
   <ui-select-match placeholder="Choose strength">
   <span ng-bind="$select.selected.name"></span>
   </ui-select-match>
   <ui-select-choices repeat="item in (mappingStrengthList | filter: $select.search) track by item.id">
   <span ng-bind="item.name"></span>
   </ui-select-choices>
   </ui-select>
 </div> 
<div class="col-sm-4">
   <ui-select class="col-sm-12 no-padding" ng-model="mappingStrengthList.selected">
   <ui-select-match placeholder="Choose strength">
   <span ng-bind="$select.selected.name"></span>
   </ui-select-match>
   <ui-select-choices repeat="item in (mappingStrengthList | filter: $select.search) track by item.id">
   <span ng-bind="item.name"></span>
   </ui-select-choices>
   </ui-select>
 </div>

控制器:

ListService.getList('mapping-strength').then(function (results) {
                $scope.mappingStrengthList = results;
            }, function (error) {
                console.log(error);
            });

enter image description here

2 个答案:

答案 0 :(得分:1)

如果您想要选择不同的值,那么您的模型应该是不同的,现在您在两者上使用:ng-model="mappingStrengthList.selected"

我认为您甚至不应该使用mappingStrengthList填充该选项的数据,该模型应该是其他内容。

答案 1 :(得分:0)

$scope.mappingStrengthList.selected = 'YOUR-VALUE-WHICH-YOU-WANT-SET'