####BackboneJS Sort Collection asc/desc
Last active
January 6, 2016 06:23
-
-
Save kurtisdunn/bd5e72fbb8c8c46c582e to your computer and use it in GitHub Desktop.
BackboneJS Sort Collection asc/desc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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