I've recently got up to speed with Knockout and I think it's a fantastic framework. However I have one concern.
I'm finding that in non-trivial binding cases, I have snippets of javascript code creeping into my view (markup). In fact quite a few code samples in the Knockout documentation demonstrate this too.
Does this make Knockout inherently obtrusive?
Should I just accept it for what it is and not be worried in practice?
Or are there any patterns/techniques I should be employing to make Knockout unobtrusive?
ko. dataFor(element) - returns the data that was available for binding against the element. ko. contextFor(element) - returns the entire binding context that was available to the DOM element.
Knockout is a JavaScript library that helps you to create rich, responsive display and editor user interfaces with a clean underlying data model.
To activate Knockout, add the following line to a <script> block: ko. applyBindings(myViewModel); You can either put the script block at the bottom of your HTML document, or you can put it at the top and wrap the contents in a DOM-ready handler such as jQuery's $ function.
Knockout. js is a minimalist JavaScript framework for web application development. It is a JavaScript library that allows binding HTML elements against any data model. It is primarily used for creating rich and responsive display as well as editor user interfaces with a clean, underlying data model.
Great question. I've been writing complex KnockoutJS views for awhile and was never satisfied until I switched to Ryan Niemeyer's class binding provider.
The Knockout ClassBindingProvider allows you to declare your bindings in a JavaScript object and then reference them from a data-class
attribute similar to how css classes work. It works great!
See an example TodoMVC app.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With