2016-09-17 1 views
0

나는 이것과 비슷한 객체의 객체를 반환하는 서비스를 호출하고 있습니다. userCollections는 저장되는 변수입니다.스마트 테이블 st-sort Angular JS - 정렬되지 않은 객체의 객체

{ 
    1: { 
     id: "A1", 
     name: "B1" 
    }, 
    2: { 
     id: "A1", 
     name: "B1" 
    }, 
    3: { 
     id: "A1", 
     name: "B1" 
    }, 
    4: { 
     id: "A1", 
     name: "B1" 
    }, 
    5: { 
     id: "A1", 
     name: "B1" 
    }, 
} 

이것은 테이블에 데이터를 표시하는 방법입니다.

<table class="table table-hover" st-table="DisplayCollection" st-safe-src="userCollections"> 
    <thead class="thead-inverse text-uppercase"> 
    <tr> 
     <th st-sort="id" st-sort-default="true" class="cursor-pointer">Name</th> 
     <th st-sort="name" class="cursor-pointer">Email</th> 
    </tr> 
    </thead> 

    <tbody ng-repeat="(cname, cdata) in DisplayCollection"> 
    <tr class="cursor-pointer" ng-repeat="collection in cdata"> 
     <td ng-bind="collection.full_name | ellipsis:25:false"></td> 
     <td ng-bind="collection.email | ellipsis:25:false"></td> 
    </tr> 
    </tbody> 
</table> 

st-sort가 작동하지 않습니다. 객체의 객체에서 어떻게 작동하게합니까?

개체 작업을 위해 개체 키가 필요하므로 개체 개체를 개체 배열로 변환 할 수 없습니다.

어떤 방법으로 정렬 할 수 있습니까?

답변

0

자바 스크립트 개체는 순서가없고 정렬 할 수 없습니다.

배열에 데이터를지도하고 각 항목

var data = { 
 
    1: { 
 
    id: "A1", 
 
    name: "B1" 
 
    }, 
 
    2: { 
 
    id: "A1", 
 
    name: "B1" 
 
    }, 
 
    3: { 
 
    id: "A1", 
 
    name: "B1" 
 
    }, 
 
    4: { 
 
    id: "A1", 
 
    name: "B1" 
 
    }, 
 
    5: { 
 
    id: "A1", 
 
    name: "B1" 
 
    }, 
 
} 
 
var newArray = Object.keys(data).map(function(key) { 
 
    var obj = angular.copy(data[key]); 
 
    obj.key = key; 
 
    return obj; 
 
}); 
 
console.log(newArray)
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.9/angular.min.js"></script>

의 속성으로 키를 추가