3
votes

I'm use a Marionette Composite View with the emptyView property to render a simple template when the collection for the composite view has no models. emptyView works fine on multiple places in my app, but for some reason there's one view where the emptyView is rendering twice on the page.

My initial thought was the the view was re-rendering and not removing itself when the collection was synced. A console.log in the initialize function reveals that initialize is only being called once though.

class AllLists extends Backbone.Marionette.CompositeView
  itemView: List
  emptyView: NoLists
  template: AllListsTemplate
  className: 'lists'

  initialize: (options) ->
    @collection.fetch()
    console.log 'lists ', @collection, @model

class NoLists extends Backbone.Marionette.ItemView
  template: NoListsTemplate
  tagName: 'li'
  className: 'no-lists'

As you can see, there's nothing too crazy going on here. The empty list template is just a simple h4 tag with some text in it.

Any ideas as to what might be causing this?

1

1 Answers

4
votes

This is a known bug in the v0.9.3 release, and is fixed in the up-coming v0.9.4 release.

The fix is currently in the dev branch as a release preview, if you would like to get it now https://github.com/derickbailey/backbone.marionette/tree/dev

And there are a few pull requests that provided fixes if you want to patch your version with code from one of them: https://github.com/derickbailey/backbone.marionette/pull/175