0
<ui-select id="facility" multiple ng-model="IdRequest.formData.facilityRequestedArray"  validation="required" ng-disabled="IdRequest.formData.applicantReadOnly" class="drop-down">
  <ui-select-match allow-clear="true" placeholder="{{'select'|translate}}">
    {{$item.displayText}}
  </ui-select-match>
  <ui-select-choices repeat="facility.id as facility in IdRequest.facilityList">
    {{facility.displayText}}
  </ui-select-choices>
</ui-select>

错误:[ngRepeat:dupes] 不允许在转发器中重复。使用“track by”表达式指定唯一键。中继器:$select.selected 中的 $item,重复键:数字:1,重复值:1

4

2 回答 2

1

我在使用 ui-select(版本 2.1.3)时遇到了同样的问题。所选项目是通过 ajax 加载的,将显示正确的选择,但是当单击以选择另一个选项时,已选择的选项在可能的选项内,并且当再次选择时,会触发重复错误。

我决定不挖掘源代码,而是强制从脚本中刷新指令。

这是修复:HTML

<ui-select multiple="true" ng-model="x.itemsSelected" theme="bootstrap">
    <ui-select-match placeholder="Select Eligibility Item...">{{$item.name + ' #' + $item.id}}</ui-select-match>
    <ui-select-choices repeat="item.id as item in x.itemsAvailable | filter: $select.search track by $index" refresh="uiSelectRefreshFix($select)" refresh-delay="1000">
        <div ng-bind-html="item.name + ' #' + item.id | highlight: $select.search"></div>
    </ui-select-choices>
</ui-select>

控制器

// ui-select bugfix.
$scope.uiSelectRefreshFix = function () {

    if ($scope.uiSelectFix) return; 
    $scope.uiSelectFix = true;

    var fix = $scope.x.itemsSelected;
    $scope.x.itemsSelected = [];

    setTimeout(function() {
        $scope.$apply(function(){
            $scope.x.itemsSelected = fix;
        });
    }, 100)
    console.log([model, query]);
}
于 2016-09-01T02:16:32.417 回答
0

将您的倍数设置为 true ,如下所示:

<ui-select id="facility" multiple='true' ng-model="IdRequest.formData.facilityRequestedArray"  validation="required" ng-disabled="IdRequest.formData.applicantReadOnly" class="drop-down">

请参阅此 github 链接:https ://github.com/angular-ui/ui-select/issues/366

如果您有重复的设施,还可以通过 $index 将轨道添加到中继器,如下所示:

<ui-select-choices repeat="facility.id as facility in IdRequest.facilityList track by $index">
于 2015-04-20T18:17:54.857 回答