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
console.log(c.m1.length)
console.log(c.m2.length)
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
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
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
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?
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:
|