Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rearrange index of models within a Marionette Composite View

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.

like image 752
Subhajit Ghosh Avatar asked Dec 31 '25 02:12

Subhajit Ghosh


1 Answers

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'); }
});
like image 154
Tholle Avatar answered Jan 02 '26 16:01

Tholle