Permalink
Browse files

Fixed appendChildTo not working when view is not added to document

  • Loading branch information...
1 parent 5ff7899 commit 589866de63f1c05059e77c58ad4ef31804cb9c64 @alexmreis alexmreis committed with jferris Aug 17, 2012
View
2 lib/assets/javascripts/backbone-support/composite_view.js
@@ -44,7 +44,7 @@ _.extend(Support.CompositeView.prototype, Backbone.View.prototype, {
appendChildTo: function (view, container) {
this.renderChild(view);
- $(container).append(view.el);
+ this.$(container).append(view.el);
},
prependChild: function(view) {
View
16 spec/javascripts/composite_view_spec.js
@@ -74,12 +74,22 @@ describe("Support.CompositeView", function() {
describe("#appendChildTo", function() {
it("appends child into the given element", function() {
$("#test1").text("Append to this!");
-
+ $("#test").append($("#test1"));
+
var view = new blankView({el: "#test"});
view.appendChildTo(new orangeView(), "#test1");
-
- expect($("#test").text()).toEqual("");
+
expect($("#test1").text()).toEqual("Append to this!Orange!");
+
+ $("#test1").remove();
+ expect($("#test").text()).toEqual("");
+ });
+
+ it("appends child into a sub-element even if it is not added to the document", function() {
+ var view = new blankView({el: $('<div><div class="inside">Append to this!</div></div>')});
+ view.appendChildTo(new orangeView(), ".inside");
+
+ expect($(view.el).find('.inside').text()).toEqual("Append to this!Orange!");
});
});

0 comments on commit 589866d

Please sign in to comment.