Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Ok, so I am trying to sort out my json data into a table:

{
    "0": {
        "1": {
            "airdate": "2011-12-04", 
            "file_size": 368279154, 
            "location": "filepath", 
            "name": "episodename", 
            "quality": "Unknown", 
            "release_name": "", 
            "status": "Downloaded", 
            "subtitles": ""
        }
    }, 
    "1": {
        "1": {
            "airdate": "2011-12-04", 
            "file_size": 368279154, 
            "location": "filepath", 
            "name": "episodename1", 
            "quality": "Unknown", 
            "release_name": "", 
            "status": "Downloaded", 
            "subtitles": ""
        }, 
        "2": {
            "airdate": "2011-12-04", 
            "file_size": 368279154, 
            "location": "filepath", 
            "name": "episodename2", 
            "quality": "Unknown", 
            "release_name": "", 
            "status": "Downloaded", 
            "subtitles": ""
        }, 
        "14": {
            "airdate": "2011-12-04", 
            "file_size": 368279154, 
            "location": "filepath", 
            "name": "episodename14", 
            "quality": "Unknown", 
            "release_name": "", 
            "status": "Downloaded", 
            "subtitles": ""
        }
    }    

The problem is my angular ng-repeat lists it in order alphabetically ex 1, 14, 2... I can't seem to work with this object to take the key and set it as an ID parameter for the object but I thought that would be the best option. any suggestions would be helpful. I would like to note I cannot alter the server side api.

share|improve this question
1  
Can you post ng-repeat code too? –  Rishi Prakash 18 hours ago

1 Answer 1

if the order of some collection is important, you should consider using array instead.

if you stick using object, the way is to create an array to keep the object's keys for orderfing purpose

the prototype

scope.obj = {"1":{}, "2":{}, "14":{}};
scope.objKeys = ['1', '2', '14'];

<div ng-repeat="key in objKeys">
    {{obj[key]}}
</div>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.