I have several views in my project and each applies bindings on its own tag like this:

(note: periods represents more code removed to show the problem I have, I created a fiddle a bit more complete here: http://jsfiddle.net/EYB8E/)

HTML

<div id="ui-main"> 
    ... html code bound to mainViewModel here
<div/>

...

<div id="ui-partial"> 
    ...
</div>

javascript

function MainViewModel() {...};

var mainViewModel = new MainViewModel();
ko.applyBindings(mainViewModel, document.getElementById("ui-main"));

...
function PartialViewModel() {...};
ko.applyBindings(partialViewModel, document.getElementById("ui-partial"));

but the second applyBindings does not apply because: "Error: You cannot apply bindings multiple times to the same element.". (see it in jsFidle: http://jsfiddle.net/EYB8E)

I cannot figure out what is wrong.

有帮助吗?

解决方案

Your <div /> should be </div>.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top