I am experiencing that the nested div wont bind with the VM. Any ideas?I am trying the following and it breaks any ideas?
<div id="div1">
<div id="div2">
</div>
</div>
If I try this is works fine:
<div id="div1">
</div>
<div id="div2">
</div>
Javascript:
ko.applyBindings(vm1, document.getElementById('div1'));
ko.applyBindings(vm2, document.getElementById('div2'));
Any ideas?
A nested VM (nested virtual machine) is a virtual machine contained within another VM. Nested VMs are used for testing out hypervisors and new operating systems in lab environments. Administrators using one hypervisor can nest a competitive hypervisor to try its features.
Nested virtualization lets you run virtual machine (VM) instances inside of other VMs so you can create your own virtualization environments. To support nested virtualization, Compute Engine adds Intel VT-x instructions to VMs, so when you create a VM, the hypervisor that is already on that VM can run additional VMs.
When you bind div1
it will bind everything including what is in div2
. When you bind div2
it will bind the elements again. This is not a good situation, as elements will have multiple event handlers attached to them. Otherwise, one of the applyBindings will likely error out as the elements are not expecting to bind against a different view model.
The article here lays out a way to protect the inner element from being bound by the outer call: http://www.knockmeout.net/2012/05/quick-tip-skip-binding.html
The other option is to use a single view model like:
var viewModel = {
vm1: vm1,
vm2: vm2
};
ko.applyBindings(viewModel);
Then, bind like:
<div id="div1" data-bind="with: vm1">
<div id="div2" data-bind="with: $root.vm2">
</div>
</div>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With