Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit 2e8cfdc85232b055f4646ff936f22b7492b2b64e 1 parent eb38830
@derickbailey derickbailey authored
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();
},
Please sign in to comment.
Something went wrong with that request. Please try again.