justspamjustin / BossView

Manage your Marionette.js views like a boss! Manages events and rendering of sub-views.
http://justspamjustin.github.io/BossView/
MIT License
48 stars 6 forks source link

Allow subviews to use different collections and models than the parent #5

Closed abritinthebay closed 10 years ago

abritinthebay commented 10 years ago

Right now it only uses this.model or this.collection when setting up the view.

This makes no sense if you have, for example, a collectionview subview that doesn't require the same collection OR more than one collectionview subview.

Is there a way to set this up currently (if so, it's non-obvious and not documented).

justspamjustin commented 10 years ago

This example: https://gist.github.com/justspamjustin/6359269#file-bossviewdocssubviews-js shows how you can do that. It's not very straightforward on the home page. But basically you just pass a function that returns an instance of your subview. You can pass any model or collection to that instance.

...
subViews: {
  myCollectionView: function() {
    return new Marionette.CollectionView({
      collection: this.myOtherCollection
    });
  }
}
...