0

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

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

在此处输入图像描述

4

2 回答 2

1

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

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

于 2016-05-29T18:36:30.127 回答
0
$scope.mappingStrengthList.selected = 'YOUR-VALUE-WHICH-YOU-WANT-SET'
于 2016-05-29T18:34:38.150 回答