以下数据通过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 = [];
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>
但是,每次选择项目时,它都会对所选项目进行排序id
。例如,如果您选择“apple”然后选择“boat”,则selected
项目将是“boat”和“apple”(按此顺序!)。
如何保留订单并禁用此自动排序?