2016-11-01 2 views
0

에 의한 주문 오브젝트 나는이 객체가 현재 정렬입니다. 어떤 아이디어?해 orderBy 값

+0

이 객체를 키와 이름이있는 객체의 배열로 변형하고 해당 배열에서 orderBy를 사용합니다. –

답변

2

orderBy 개체, 키 및 값의 배열이 더 좋습니다.

필터 방법을 시도해보십시오

자바 스크립트 :

var app = angular.module('myapp',[]); 

app.filter('orderObjectBy', function(){ 
return function(input, attribute) { 
    if (!angular.isObject(input)) return input; 

    var array = []; 
    for(var key in input) { 
     array.push(input[key]); 
    } 

    array.sort(function(a, b){ 
     if(a < b) return -1; 
     if(a > b) return 1; 
     return 0; 
    }); 
    return array; 
} 
}); 

HTML :

<md-option ng-repeat="(code, country) in itemObjects | orderObjectBy:'country'" value="{{code}}">{{country}}</md-option> 

code example

재밌게.