Skip to content

Collection Sort on Model Change #689

Closed
@snoe

Description

@snoe

The documentation for Collection.sort says

a collection with a comparator function will maintain itself in proper sort order at all times.

Yet, if my comparator is

comparator: function(model) {
    return model.get("name");
}

Then if I change the name:

model.set({name: 'zzz'});

and in the change event I use indexOf, I get the wrong index:

model.bind('change', changed);
changed = function(model) {
    var index = model.collection.indexOf(model)
     // index is based off the old name
}

This is because the collection does not resort automatically on change. I think the documentation should change, or preferably, a this.sort({silent}) in Collection._onModelEvent should occur.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions