I have the following code :
Campaign.Collection = Backbone.Collection.extend({initialize: function() {
},
comparator: function(item) { return item.get('Name'); }
}
I call collection.sort() and seems to work and sorts models regarding Name field the problem is that gives higher priority to uppercase letters example ('Some test' < 'more test') is there a way to override the behavior ?
Backbone. js is a model view controller (MVC) Web application framework that provides structure to JavaScript-heavy applications. This is done by supplying models with custom events and key-value binding, views using declarative event handling and collections with a rich application programming interface (API).
Backbone. Backbone has been around for a long time, but it's still under steady and regular development. It's a good choice if you want a flexible JavaScript framework with a simple model for representing data and getting it into views.
Backbone is a JavaScript MVC library and that's a key difference.
It is also known as the heart of the JavaScript application. Model contains dynamic data and its logic. It performs various types of action on the data like validation, conversion, computed properties, access control etc. 1.
The easiest fix is to simply do the following:
Campaign.Collection = Backbone.Collection.extend({
initialize: function() {},
comparator: function(item) { return item.get('Name').toLowerCase(); }
};
This will convert all to lower case before comparing so it will compare in a manner that ignores case.
For a case insensitive comparison, use the native JS function toLowerCase
:
Campaign.Collection = Backbone.Collection.extend({initialize: function() {
},
comparator: function(item) { return item.get('Name').toLowerCase(); }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With