Backbone.js 使用集合引用初始化CollectionView

Backbone.js 使用集合引用初始化CollectionView,backbone.js,marionette,Backbone.js,Marionette,在CollectionView主干木偶对象的初始化函数中,我执行以下操作: this.collection_addresses = new AddressCollectionView({ el: 'ul.addresses', collection: options.user.get("addresses") }); 然而,AddressCollectionView永远不会在options.user.get(“addresses”)中引用的对象发生更改时更新,我以为Marion

在CollectionView主干木偶对象的初始化函数中,我执行以下操作:

this.collection_addresses = new AddressCollectionView({
    el: 'ul.addresses',
    collection: options.user.get("addresses")
});
然而,
AddressCollectionView
永远不会在
options.user.get(“addresses”)
中引用的对象发生更改时更新,我以为Marionette会自动处理这个问题。用户对象使用fetch更新。有什么想法吗

编辑#1 只是为了澄清集合视图是这样的

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

谢谢。

从v1.0.3源代码中,以下是collectionview收听的事件

_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);
    }
  },

collectionView接受itemView对象定义(而不是实例)。collectionview使用集合中每个项的模型初始化此itemView。我将扩展marionette的itemview类,并在模型上侦听您的更改事件,然后将itemview对象定义(而不是实例)注入collectionview。

从文档中可以看出,您仍然需要“侦听”集合events@AstDerek为什么?collectionview初始化器通常侦听添加/删除/重置操作,而不是添加/删除/重置集合。您正在修改该集合上的模型。您的itemView需要在其initialize块中侦听模型更改事件,然后应该执行此操作。