Tobias, thanks for the feedback. Indeed I cannot quite do as you
suggest, as I'm iterating over a raw object{}, not an Array(), thus I
can't sort the obj in advance.
You can represent order and key/val relationship with a
more complex data structure. I do this all the time.
Stuff each key/val pair of your object into an array,
then use your custom sort function to compare the values of
each object in the array (http://tobiah.org/foo.html).
<script>
var ob = {
'dog': 'canine',
'cow': 'bovine',
'horse': 'equestrian',
'cat': 'feline'
}
console.log(ob_sorter(ob));
function ob_sorter(ob){
var holder = [];
for(var x in ob){
holder.push({key: x, val: ob[x]});
}
holder.sort(val_sort);
return holder
}
function val_sort(left, right){
return left.val > right.val
}
</script>
Then you can utilize the sorted pairs in a slightly different way:
<span ng-repeat='pair in my_ob'>
{{pair.key}}{{pair.val}} or whatever you wanted to do with them.
</span>
If you want to sort by keys, just use left.key > right.key in the val_sort().
Tobiah
--
You received this message because you are subscribed to the Google Groups
"AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.