Listen to add / change collections as an attribute of the view model

I have a Measure View, and it has an associated measurement model that has two collections: RepresentationsCollection and BeatsCollection. In the Measure View, there are subviews of the views of the child elements, each of which has its own view model, and all view models have the same link attribute for the Measure View BeatsCollection.

I know that if you listen to an event change, the collection will not respond when something is added. You must use bind. Documents are not the best. So, if the child view view looks like this:

here is a visual

representation.View = Backbone.View.extend({
  initialize: function(options) {
    // this.beatsCollection is a reference to the Parent Measure View attribute beatsCollection which is a collection
    this.model.listenTo(this, 'change:beatsCollection', this.render);
    this.model.on('change:beatsCollection', this.render, this);
    this.bind.listenTo(this, 'change:beatsCollection', this.render);
  },

and here is the model:

representation.Model = Backbone.Model.extend({
  initialize: function(options) {
    console.log(options); 
    this.idAttribute = options.idAttribute;
    this.type = options.type;
    this.beatsCollection = options.beatsCollection;
 } 

, , , ?

Plnkr: http://plnkr.co/edit/z4mWqo1v0nDe13TiB9r3?p=preview
" ".
-, " " , . -, " ", . Representation.js, , " "

+4
1

Plnkr: http://plnkr.co/edit/JtyxnhaGlPVijhbRPt5v?p=preview

.

initialize: function(options) {
  if(options.model){this.model=options.model;}
  this.model.listenTo(this, 'change:beatsCollection', this.render);
  this.model.on('change:beatsCollection', this.render, this);
  this.model.on('change:beatsCollection', this.render, this);
  //this.model.on('destroy', this.remove, this);
},

initialize: function(options) {
  if(options.model){this.model=options.model;}
  this.listenTo(this.model.beatsCollection,  'add remove reset', this.render);
},
+3

All Articles