Backbone: reverse collection order with comparator

Backbone: reverse collection order with comparator

By : Alex
Date : November 29 2020, 01:01 AM
this one helps. I'm building a Backbone app which displays a list of books, but when I add a new book, through the Edit view, he goes to the bottom of the list instead to the top. So basically I want to reverse the order of my collection with a Comparator but what I tried it's not working: , Why not a simple prepend instead of append
code :

Share : facebook icon twitter icon
Backbone collection comparator

Backbone collection comparator

By : ESKrueger
Date : March 29 2020, 07:55 AM
will be helpful for those in need I'm using backbone and marionette, , The problem is that you're using a bound function as the comparator:
code :
comparator : (item) =>
if (_.isString(this.comparator) || this.comparator.length === 1) {
  this.models = this.sortBy(this.comparator, this);
} else {
  this.models.sort(_.bind(this.comparator, this));
class C
    m1: (x) -> x
    m2: (x) => x

c = new C
class C
    m: (x) => x
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
comparator: (item) -> item.id
Backbone Collection is Half-Sorted When Comparator is Used

Backbone Collection is Half-Sorted When Comparator is Used

By : hien beng
Date : March 29 2020, 07:55 AM
like below fixes the issue I am using backbone's collection model to display a sorted list of strings on a backbone view. Here is the model and the comparator: , Here is a working code.
code :
var MenuItems = Backbone.Collection.extend({
    comparator: function (a, b) {
        if (a.get('name') < b.get('name')) {
            return -1;
        } else if (a.get('name') > b.get('name')) {
            return 1;
Backbone.js collection comparator not sorting by number

Backbone.js collection comparator not sorting by number

By : P Frank
Date : March 29 2020, 07:55 AM
To fix this issue After much digging, it looks like the collection was actually sorting, it just wasn't doing a full re-render after each new fetch({remove: false}). I added a listener to the CompositeView like so:
code :
class MyClass extends Marionette.CompositeView
  initialize: ->
    @collection.on "sync", () => @render()
Backbone: reverse string comparator

Backbone: reverse string comparator

By : user3718688
Date : March 29 2020, 07:55 AM
hope this fix your issue Well, specifying .comparator really just delegates to _.sortBy as the docs specify which just calls _.property. So no, you can pass a function (a _.pluck with a - between the arguments in the reverse order) but I suspect you already know this.
Can Backbone render a collection in reverse order?

Can Backbone render a collection in reverse order?

By : xv6prob
Date : March 29 2020, 07:55 AM
I hope this helps . To go through collection in the reverse order I usually use a construction like this:
Related Posts Related Posts :
  • angular 6 Please add a @NgModule annotation
  • Trying to cast element ID to class selector in jQuery
  • Swipe JS - Display 3 Slides at a time
  • Jasmine test to call function when value is null
  • Redux reducer gets string instead of object
  • Keep chrome javascript running even if page reload
  • The event.target.value is not insert the userinput into a variable
  • Exporting HTML tables to Excel (.xls) in a separate sheet
  • Jquery tooltip on dialog close button
  • access variable inside anonymous function from outside
  • How come func is called from a function?
  • How to change add and remove active class in JavaScript
  • how to toggle a specific div in javascript
  • How to get all the values from multiple keys of an array of object?
  • jQuery bind() unbind() and on() and off()
  • regular expression to find DD Month YYYY from a string
  • How to upload files from web client (HTML/jQuery form) to your Dropbox folder
  • Backbone history and require.js issue
  • Confusion over Classical and Prototypal Inheritance Javascript
  • How to take screen shot of current webpage using Javascript/JQuery?
  • Store meridiem in a variable
  • class declared inside closure vs standard class without closure
  • javascript confirm box always return true
  • dynamically changing the size of font size based on text length using css and html
  • Node.js - Getting the host IP address while on Amazon EC2
  • Confusing CSS, can anyone explain please
  • How to install v8-profiler on Windows 8 (64 bit) using npm?
  • Resolve promise based on another promise
  • google maps adding overlay layer above UI and markers
  • Style specific letter?
  • RangeError: Maximum call stack size exceeded with array.slice
  • node rest client get with local variable
  • If condition not executes while mouse move fastly
  • Count the number of displayed elements in a HTML list
  • Locate JavaScript source code in Emacs
  • Clean, Modular Code vs MV* Frameworks
  • infinite scroll without loading image
  • What do printers ignore?
  • jQuery UI .tabs() Contentless tab?
  • Execute Javascript alert() after page (visually) loaded
  • JavaScript - duplicating array doesn't work
  • Excessive clickable area below image
  • JavaScript Regex: Replace |b| with <b>
  • Unexpected value change in 2D array in JavaScript
  • Function doesnt see parameter as a array of objects
  • jQuery fetch keypress event on chrome and IE
  • How to enable jquery validate localization?
  • Cassandra map collection returned by node.js Helenus looks odd
  • angular ng-repeat with multiple filter options
  • Selecting Children without ID or Class names
  • How to uncheck a group of checkboxes when another checkbox is checked
  • Is hiding content by Javascript or jQuery Worth trying
  • Load XUL resource using javascript
  • XML to HTML text area from server file system
  • set focus() on textbox on form onload
  • es lint '' is assigned a value but never used' eventhough i have used it
  • Can "name" attribute be used for custom VueJS components
  • Get innerHTML of content when it is clicked
  • HTTPS causes CSS animations to not load? Very confused
  • How to hide other div apart from touched div to the band
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org