Browse files

collection view can attach child view from existing DOM on init. fixes

  • Loading branch information...
1 parent eb38830 commit 2e8cfdc85232b055f4646ff936f22b7492b2b64e @derickbailey derickbailey committed Oct 4, 2012
Showing with 33 additions and 1 deletion.
  1. +1 −0 changelog.md
  2. +31 −0 spec/javascripts/collectionView.attachToDOM.spec.js
  3. +1 −1 src/marionette.collectionview.js
View
1 changelog.md
@@ -33,6 +33,7 @@
* CollectionView / CompositeView
* Cleaned up the `getItemViewContainer` code, and improved the error that is thrown when the specified container element is not found
+ * Can attach existing view instance w/ existing DOM element as child of collection view / composite view, in parent's `initialize` function
* Misc
* jQuery ($) support now works from global `$` or `window.jQuery`
View
31 spec/javascripts/collectionView.attachToDOM.spec.js
@@ -0,0 +1,31 @@
+describe("attaching collection view to existing DOM structure", function(){
+
+ describe("when initializing a collection view", function(){
+
+ var CollectionView = Marionette.CollectionView.extend({
+ initialize: function(){
+ var m = new Backbone.Model();
+ var v = new Backbone.View({
+ el: "#foo",
+ model: m
+ });
+
+ this.storeChild(v);
+ }
+ });
+
+ var cv;
+
+ beforeEach(function(){
+ cv = new CollectionView({
+ collection: new Backbone.Collection()
+ });
+ });
+
+ it("should be able to store a new child view that was attached to an existing DOM element", function(){
+ expect(_.size(cv.children)).toBe(1);
+ });
+
+ });
+
+});
View
2 src/marionette.collectionview.js
@@ -5,8 +5,8 @@
// and renders an individual ItemView for each model.
Marionette.CollectionView = Marionette.View.extend({
constructor: function(){
- Marionette.View.prototype.constructor.apply(this, arguments);
this.initChildViewStorage();
+ Marionette.View.prototype.constructor.apply(this, arguments);
this.initialEvents();
this.onShowCallbacks = new Marionette.Callbacks();
},

0 comments on commit 2e8cfdc

Please sign in to comment.