There are a couple ways that you can go on this one.
One choice is to create an overall view model that is a container for your sub view models.
So, you would have:
var viewModel = {
subViewModelA: { name: "Bob" },
subViewModelB: { name: "Ted" }
};
ko.applyBindings(viewModel);
and you would can bind against it (with nested models) like:
<div data-bind="with: subViewModelA">
<div data-bind="text: name"></div>
<div data-bind="with: $root.subViewModelB">
<span data-bind="text: name"></span>
</div>
</div>
Another option is to create a simple binding that will stop KO from applyBindings to its children and then calling applyBindings with another model inside of it.
It would look like:
ko.bindingHandlers.stopBindings = {
init: function() {
return { 'controlsDescendantBindings': true };
}
};
var viewModelA = { name: "Bob" };
var viewModelB = { name: "Ted" };
ko.applyBindings(viewModelA);
ko.applyBindings(viewModelB, document.getElementById("inner"));
You would bind against it like:
<div>
<div data-bind="text: name"></div>
<div data-bind="stopBindings: true">
<div id="inner">
<span data-bind="text: name"></span>
</div>
</div>
</div>
Hope this helps.