diff --git a/spec/rivets/binders.js b/spec/rivets/binders.js index 71c836709..7507f7081 100644 --- a/spec/rivets/binders.js +++ b/spec/rivets/binders.js @@ -199,6 +199,24 @@ describe("Rivets.binders", function() { // 1 for the comment placeholder Should(fragment.childNodes.length).be.exactly(1); }); + + it("rebindes nested if", function() { + var nestedEl = document.createElement("div") + nestedEl.setAttribute("rv-if", "data.showNested"); + nestedEl.innerHTML = "{ data.countNested }"; + el.appendChild(nestedEl); + + var view = rivets.bind(fragment, model); + + model.data.countNested = "1"; + model.data.showNested = true; + Should(nestedEl.innerHTML).be.exactly("1"); + model.data.show = false; + model.data.show = true; + model.data.countNested = "42"; + + Should(nestedEl.innerHTML).be.exactly("42"); + }); }); describe("Custom binder with no attribute value", function() { diff --git a/src/binders.coffee b/src/binders.coffee index cffb05076..759a76178 100644 --- a/src/binders.coffee +++ b/src/binders.coffee @@ -111,7 +111,9 @@ Rivets.public.binders.if = el.parentNode.removeChild el unbind: -> - @nested?.unbind() + if @nested + @nested.unbind() + @bound = false routine: (el, value) -> if !!value is not @bound