Skip to content

Commit

Permalink
Merge pull request #851 from ericmatthys/master
Browse files Browse the repository at this point in the history
Return the newly added view from addItemView in CollectionView.
  • Loading branch information
samccone committed Jan 13, 2014
2 parents 1fd95a1 + db61132 commit f600037
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
20 changes: 20 additions & 0 deletions spec/javascripts/collectionView.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,4 +836,24 @@ describe("collection view", function(){
});
});

describe("when returning the view from addItemView", function(){
var childView;

beforeEach(function(){
var model = new Backbone.Model({foo: "bar"});

var CollectionView = Backbone.Marionette.CollectionView.extend({
itemView: ItemView
});

var collectionView = new CollectionView({});

childView = collectionView.addItemView(model, ItemView, 0);
});

it("should return the item view for the model", function(){
expect(childView.$el).toHaveText("bar");
});
});

});
2 changes: 2 additions & 0 deletions src/marionette.collectionview.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ Marionette.CollectionView = Marionette.View.extend({

// this view was added
this.triggerMethod("after:item:added", view);

return view;
},

// Set up the child view event forwarding. Uses an "itemview:"
Expand Down

0 comments on commit f600037

Please sign in to comment.