I have been looking but cannot find the documentation for applyBindings()
. What can the second parameter legally contain? Can it be an array of elements? Must it be a single element? Can the bindings be applied to the child elements of two separate nodes by calling applyBindings twice?
ko.applyBindings(myViewModel, div1);
ko.applyBindings(myViewModel, div2);
KnockoutJS is open source. From the relevant file:
So yes, it seems it must be a single DOM node. To be more specific, the nodeType is must be either 1 (
ELEMENT_NODE
) or 8 (COMMENT_NODE
), otherwise an Error is thrown.The relevant documentation ("Activating Knockout") is less explicit that it must be a DOM node, but (see emphasis, added by me) does kind of say the same thing:
As long as nodes don't share part of the tree (e.g. they're siblings) you can call applyBindings safely on each of the nodes (in fact, that's one reason to use the second argument).
See this related question for a typical use case.
In case anyone is looking to use classes for implementing this
Can be found at the following link... http://knockoutjs.com/documentation/observables.html
if you are using JAVA Script then go for root node element
In my case HTML is like this :
remember to Use document.elementByID because it requires root node