0
votes

In my initialize function of a CollectionView Backbone Marionette object, I'm doing the following:

this.collection_addresses = new AddressCollectionView({
    el: 'ul.addresses',
    collection: options.user.get("addresses")
});

However the AddressCollectionView is never updated whenever the object referenced in options.user.get("addresses") is changed, I thought Marionnette is handling this automatically. The user object is updated using a fetch. Any thoughts?

Edit #1 Just to clarify the collection view is like this

var AddressCollectionView = Backbone.Marionette.CollectionView.extend({
    itemView: AddressItemView,
    tagName: 'ul'
});

Thanks.

1
From the docs it seems you still need to "listen to" the collection eventsAst Derek
@AstDerek why? the collectionview initailizer usually listens to the add/remove/resetYehia A.Salam
you aren't adding/removing/resetting the collection. You are modifying a model on that collection.Matt Broekhuis

1 Answers

0
votes

from the v1.0.3 source code, here are the events the collectionview listens to

_initialEvents: function(){
    if (this.collection){
      this.listenTo(this.collection, "add", this.addChildView, this);
      this.listenTo(this.collection, "remove", this.removeItemView, this);
      this.listenTo(this.collection, "reset", this.render, this);
    }
  },

A collectionView accepts an itemView view object definition, (not an instance). This itemView is initialized with the model for each item in the collection by the collectionview. I would extend marionette's itemview class, and listen to your change event on your model there, and inject that itemview view object definition, (not an instance) into the collectionview.