when I inject any new elements into the DOM after ko.applyBindings(); was called, then knockout won’t recognize these new elements.
I can understand why this is happening – they are just not indexed by knockout.
So, at first I thought this would be solved by just calling ko.applyBindings() again, after adding my new elements, BUT then I realized that for every ko.applyBindings() call you make, the according events get fired multiple times. So after applying five times, a click: binding will be fired five times, so this is not a desireable solution 😉
Is there anything like ko.updateBindings() or something else, to tell knockout to, well… update the element bindings?
greetings,
Chris
Each time you invoke
ko.applyBindingsthe entire DOM is inspected for bindings. As a result you will get multiple bindings for each element if you do this more than once. If you just want to bind a new DOM element you can pass this element as a parameter to theapplyBindingsfunction:See this related question:
Can you call ko.applyBindings to bind a partial view?