Angular UI select2 - 如何停止自动排序?

Mis*_*hko 5 angularjs jquery-select2 angular-ui

通过Angular UI将以下数据附加到select2 :( 此处为实例)

JS:

$scope.items = [
  {id: 1, text: 'elephant'}, 
  {id: 2, text: 'desk'}, 
  {id: 3, text: 'car'}, 
  {id: 4, text: 'boat'}, 
  {id: 5, text: 'apple'}
];
$scope.selected = [];
Run Code Online (Sandbox Code Playgroud)

HTML:

<select ui-select2 
        multiple 
        ng-model="selected" 
        data-placeholder="Please select..." 
        style="width:200px">
  <option></option>
  <option ng-repeat="item in items" value="{{item.id}}">{{item.text}}</option>
</select>
Run Code Online (Sandbox Code Playgroud)

但是,每次选择项目时,它都会对所选项目进行排序id.例如,如果您选择"apple"然后选择"boat",则selected项目将为"boat"和"apple"(按此顺序!).

我怎样才能保留订单并禁用此自动排序?

Ada*_*dam -2

ng-options如果您使用而不是像这里ng-repeat看到的那样对每个项目执行 an 操作,看起来它会保留顺序

您所要做的就是删除这一行:

<option ng-repeat="item in items" value="{{item.id}}">{{item.text}}</option>
Run Code Online (Sandbox Code Playgroud)

然后将这样的指令添加到您的标签中:

ng-options="item.text for item in items"
Run Code Online (Sandbox Code Playgroud)

这将使整个项目对象被附加到所选列表中,而不仅仅是 ID,因此您需要考虑到这一点。