samedi 27 juin 2015

Custom sorting compare in Ember

I have a problem with sorting in Ember.

I use moment.js for handling all times in ember, I never use plain javascript date objects since I need to always be aware of timezone set by the user. When I do array.sortBy('datetime') and the properties for sorting are moment.js objects, sorting does not work, since compare method used by ember threat moment js as objects, thus returning 0. Is there any way to override default compare method as defined here - http://ift.tt/1eb11QS.

Since the method is included in mixins as Enumerable and others as closure and cannot be overridden afterwards.

Note: I don't want to use custom sorting like array.sort(function(a, b) ..., I want to use sortBy and have compare function handle the logic behind the curtain.

Thanks in adance




Aucun commentaire:

Enregistrer un commentaire