Baseline method

I have the following code:

Campaign.Collection = Backbone.Collection.extend({initialize: function() { }, comparator: function(item) { return item.get('Name'); } } 

I call collection.sort () and it seems to work and sort the models relative to the Name field, the problem is that the higher priority corresponds to the example of capital letters ("Some test" <'more test') - is there a way to override the behavior?

+6
source share
2 answers

The simplest solution is to simply do the following:

 Campaign.Collection = Backbone.Collection.extend({ initialize: function() {}, comparator: function(item) { return item.get('Name').toLowerCase(); } }; 

This will convert everything to lowercase before comparison, so it will compare in a way that ignores the case.

+11
source

For case insensitive comparisons, use the JS toLowerCase built-in function:

 Campaign.Collection = Backbone.Collection.extend({initialize: function() { }, comparator: function(item) { return item.get('Name').toLowerCase(); } } 
+6
source

Source: https://habr.com/ru/post/944990/


All Articles