Skip to content
This repository has been archived by the owner on Jun 8, 2019. It is now read-only.

Commit

Permalink
Fixed appendChildTo not working when view is not added to document
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmreis authored and jferris committed Nov 9, 2012
1 parent 5ff7899 commit 589866d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/assets/javascripts/backbone-support/composite_view.js
Expand Up @@ -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) {
Expand Down
16 changes: 13 additions & 3 deletions spec/javascripts/composite_view_spec.js
Expand Up @@ -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!");
});
});

Expand Down

0 comments on commit 589866d

Please sign in to comment.