2013-02-06 3 views
5

는 다음 데이터 Angular UI 통해 select2에 부착된다 (Live example here)각도 UI 선택 2 - 자동 정렬을 중지하는 방법?

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. 예를 들어 '사과'를 선택한 다음 '보트'를 선택하면 selected 항목이 '보트'와 '사과'가됩니다 (이 순서대로!).

어떻게 순서를 유지하고 자동 정렬을 비활성화 할 수 있습니까?

<option ng-repeat="item in items" value="{{item.id}}">{{item.text}}</option> 

: 그리고 당신이 본 here

처럼 각 항목에 대한 ng-repeat을하는 대신 ng-options를 사용하는 경우는 순서를 유지처럼

+0

이 문제는 Select2의 vanilla JS 또는 AngularUI의 경우에만 발생합니까? – ProLoser

+0

나는 이것이 왜 일어나고 있는지 전혀 모른다. 프로젝트 티켓을 열 수 있습니까? – ProLoser

+0

@ProLoser : https://github.com/angular-ui/angular-ui/issues/406 –

답변

-1

은 당신이해야 할 모든이 줄을 삭제 외모 다음과 같이 지시문을 태그에 추가하십시오.

ng-options="item.text for item in items" 

이렇게하면 전체 항목 객체가 생성됩니다 ID 대신에 선택한 목록에 추가되므로이를 고려해야합니다.

+0

'ui-select2'는'ng-options'와 호환되지 않아 비정상적인 행동을합니다. – ProLoser