Skip to content Skip to sidebar Skip to footer

Knockout Js Script Tag Does Not Apply Data Binding

I am fairly new to knockout js and the documentation maintained on official site does not provide complete html file. So I ended up writing my own script tags. When I created the h

Solution 1:

When ko.applyBindings gets called knockout searches the document for any data-bind tags and applies the appropriate bindings. Therefore, the document and any data-bind tags must already be loaded before ko.applyBindings is called or knockout will not find anything to bind to.

You have a couple of options that work:

  1. Move applyBindings to the bottom of the document where any data-binds are already in place by the time it gets called.
  2. Wrap applyBindings in a callback function so that it can be defined anywhere, but will wait to execute until the document has finished loading. For this you can use jQuery's $(document).ready(), or if you don't have jQuery see this SO question for other equivalent options

Post a Comment for "Knockout Js Script Tag Does Not Apply Data Binding"