javascript - cant sort collection in a descending fashion -


I am trying to sort my collection using .sort () But I am only collecting the archive in ascending way by code for collection,

  var ProjectCollection = Backbone.collection.extend ({url: '/ projects', model: app.Project, Sort_key: "Finish_date", comparator: function (item) {return item.get (this.sort_key);}, sortbuffed: function (field name, order type) {console.log (field name, order type); .sort_key = fieldName; if (order type == "accredited (This form (function (A, B) {returns AB});} and if (order type == "descending") {this source (function (a, b) {return ba});}}} );  

The sortbufffilled function is removed from view on a selection menu change, and it removes this function,

  sortCollection: function (e) {This Collection.sortByField ($ ('. Sort') .val (), $ ('. Command'). Val ()); Console.log (this.collection); }  

Why can not I be able to sort in a descending order? The parameters to be sent to the archive parameter are correct, and if and if others are run on the basis of the exact same parameter.

You sortBy () instead of Code> method should be used.

As explained, the collection is reformatted in the sort () method (as a new model is inserted when each time occurs) and ' Sort 'event. / P>

sortBy () method function accepts the comparator that will define the order (as per your example) (). Instead of writing

  function (a, b) {return ab}  

you should write something like

  function (A, b) {return a.get ("field") - b.get ("field")}  

In this way you compare the results of objects compared to the results instead of toValue () method of the object


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -