backbone.js - Dynamic sort in backbone collection not working -


so have basic backbone collection , model. not have view i'm rendering collection through custom template. i'd sort collection through event (clicking on column header). event sets new comparator, , fires .sort() method on collection. however, when dump collection data after .sort(), collect in same order. i'm new backbone , collections, perhaps i'm missing something. here's code:

    var ticketcollection = backbone.collection.extend({     model : ticketmodel,      initialize : function() {      },      fetch : function(options) {         options = options ? options : {};          var self = this;          $.ajax({             url : "/gettickets",             data : {},             method : "post",             cache : false,             datatype : "json",             success : function(json) {                 self.reset(json);             },             complete : options.complete         });     },      render : function() {         var self = this;          base.rendertemplate({el : $("#ticketlistcontainer"), template : "ticketlist", data : {tickets : this.tojson()}});          $("#ticketlist").find("#tdheadcompany").click(function() {             self.comparator = function(ticket) {                 ticket.get("company");             };               self.sort();             console.log(json.stringify(self.tojson()));         });      },        comparator : function(ticket) {         return ticket.get("number");     } }); 

the console.log shows collection still in original order, , not being ordered "company" i'd when company header clicked. advice? thanks!

and missing return in comparator function. pointing out, andrew!


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -