1
我在Ember中排序時遇到問題。Ember中的自定義排序比較
我使用moment.js
來處理所有時間的燼,我從來沒有使用普通的javascript日期對象,因爲我需要始終知道用戶設置的時區。當我做array.sortBy('datetime')
和排序的屬性是moment.js對象時,排序不起作用,因爲比較方法使用由ember威脅時刻js作爲對象,因此返回0.是否有任何方法來覆蓋默認比較方法,如此處定義的 - https://github.com/emberjs/ember.js/blob/v1.13.0/packages/ember-runtime/lib/compare.js#L26 。
由於該方法包含在mixins中作爲Enumerable
和其他作爲閉包,並且之後不能被覆蓋。
注意:我不希望使用自定義排序像array.sort(function(a, b) ...
,我想用sortBy
並比較函數處理幕後的邏輯。
感謝adance
是的,但'compare'用在很多地方 - 本地Array,ArrayProxy,SortableMixin等等...所以你必須在所有這些地方替換比較(包括Enumerable mixin),因爲ember已經包含了它當你重新打開Enumerable時,它不會在包含該mixin的所有地方改變。 – smolnar