When you bind div1 , it will bind everything that is in div2 . When you bind div2 , it will bind the elements again. This is not a good situation, as elements will have many event handlers associated with them. Otherwise, one of the applyBindings is most likely to be erroneous, because the elements do not expect to be bound to another view model.
This article describes how to protect an internal element from being bound by an external call: http://www.knockmeout.net/2012/05/quick-tip-skip-binding.html
Another option is to use one view model, for example:
var viewModel = { vm1: vm1, vm2: vm2 }; ko.applyBindings(viewModel);
Then bind as:
<div id="div1" data-bind="with: vm1"> <div id="div2" data-bind="with: $root.vm2"> </div> </div>
source share