Skip to content

Commit

Permalink
Merge pull request #841 from TheCloudlessSky/itemViewContainer-context
Browse files Browse the repository at this point in the history
Call the itemViewContainer in the context of the CompositeView
  • Loading branch information
samccone committed Jan 8, 2014
2 parents 04021d2 + 18d8316 commit 871083d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions spec/javascripts/compositeView-itemViewContainer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,4 +218,28 @@ describe("composite view - itemViewContainer", function(){

});

describe("when a composite view has the `itemViewContainer` specified as a function", function() {

var CompositeView = Backbone.Marionette.CompositeView.extend({
itemView: ItemView,
template: "#composite-child-container-template"
});

it("calls the `itemViewContainer` in the context of the composite view", function() {
loadFixtures("compositeChildContainerTemplate.html");
var collection = new Collection([{ foo: "bar" }, { foo: "baz" }]);
var compositeView = new CompositeView({ collection: collection });
var context;
compositeView.itemViewContainer = function() {
context = this;
return "ul";
};

compositeView.render();

expect(context).toBe(compositeView);
});

});

});
2 changes: 1 addition & 1 deletion src/marionette.compositeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Marionette.CompositeView = Marionette.CollectionView.extend({
var itemViewContainer = Marionette.getOption(containerView, "itemViewContainer");
if (itemViewContainer){

var selector = _.isFunction(itemViewContainer) ? itemViewContainer() : itemViewContainer;
var selector = _.isFunction(itemViewContainer) ? itemViewContainer.call(this) : itemViewContainer;
container = containerView.$(selector);
if (container.length <= 0) {
throwError("The specified `itemViewContainer` was not found: " + containerView.itemViewContainer, "ItemViewContainerMissingError");
Expand Down

0 comments on commit 871083d

Please sign in to comment.