Without rendering the composite view how to rearrange the index of models in the collection.
I have to sort the itemViews of a Composite View. I have used Jquery UI sortable plugin. It's working fine in the DOM but I want to reflect the rearrangement in the Backbone Collection also, with out rendering the Composite view.
You could use the comparator on your Collection, and your Composite View will take care of the rendering itself:
Example
var Member = Backbone.Model.extend({
defaults: {
name: '',
credit: 0,
memberSince: 0
}
});
// Specify what field in the model to sort with:
var Members = Backbone.Collection.extend({
model: Member,
comparator: 'credit'
});
// The comparator can also be a function:
var Members = Backbone.Collection.extend({
model: Member,
comparator: function(model) { return model.get('memberSince'); }
});
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