Skip to content

Instantly share code, notes, and snippets.

@kurtisdunn
Last active January 6, 2016 06:23
Show Gist options
  • Select an option

  • Save kurtisdunn/bd5e72fbb8c8c46c582e to your computer and use it in GitHub Desktop.

Select an option

Save kurtisdunn/bd5e72fbb8c8c46c582e to your computer and use it in GitHub Desktop.
BackboneJS Sort Collection asc/desc

####BackboneJS Sort Collection asc/desc

collection.sortBy = function () {
var models = _.sortBy(this.models, this.comparator);
if ($('#sort').hasClass('asc')) {
$('#sort').removeClass('asc').addClass('desc')
models.reverse();
return models;
}
if($('#sort').hasClass('desc')){
$('#sort').removeClass('desc').addClass('asc')
}
return models;
};
this.render(collection.sortBy())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment