0

We have written a base Backbone view class which abstracts the common methods and properties. All our view class in a module extends this base class. Also this classes use same model.

The model contains a collection. I am listening to change event of collection. Whenever there change in collection i want to listen for change event to the corresponding view. Instead this event is getting triggered for all the model instances created.

Please share your inputs to resolve this issue.

1 Answers1

0

in your base view, you can listen to model change events like this

intialize: function(options){
    ....... init code
    this.model.on('change',this.modelChanged, this);
}

then in the modelChanged handler you can trigger a custom event on the view

modelChanged: function(){
    this.trigger('modelChanged', [your args]);
}

then you can listen to the custom view event with 'on' function like we did with the model

mfarouk
  • 644
  • 5
  • 14