Is there a way to have conditional "add" events in backbone.js?

I use backbone.js for my web application, and so far it works semi-well. The problem is that sometimes I need to add elements to the collection so that they get to the top of the page, and sometimes to the bottom. Sometimes I need them to revive, and sometimes not. Is there a way to do this cleanly with backbone.js? Passing arguments to the add event would be a good way (like preend: true), but that doesn't seem to be an option ...

Thank!

+3
source share
1 answer

Extend Backbone.Collection and override the add function:

PositionCollection = Backbone.Collection.extend ({
  add: function( model, options ){
    // do your stuff
    // call the real add
    Backbone.Collection.prototype.add.call(this, model);
  }
});

, , , , , Backbone.Collection.add .

. , "" , .

+8

All Articles