I am having my backbone collection as below:
var model1 = new Backbone.Model({mode: 'EX'});
var model2 = new Backbone.Model({mode: 'AB'});
var model3 = new Backbone.Model({mode: 'DF'});
var model4 = new Backbone.Model({mode: 'AB'});
var model5 = new Backbone.Model({mode: 'DF'});
var model6 = new Backbone.Model({mode: 'AB'});
var myCollection = new backbone.Collection([model1,model2,model3,model4,model5, model6]);
Now I want this collection to be sorted in some business order, let say all models having 'DF' mode first then all models having 'AB' mode second and lastly models with mode 'EX'.
Required Output
/*my Collection.models should contains array of models in following sequence
after sorting */
[model3, model5, model2, model4, model6, model1]
I have another java script object based on which I will be deciding this sequence of modes. e.g.
var enum = {
1: 'DF',
2: 'AB',
3: 'EX'
}
So here string sorting is not useful. Can somebody suggest how can I write comparator on my backbone collection to accomplish this sorting