Knockout Generic Binding

Keywords: knockout, javascript, knockout.js, ko.applyBindingsToNode
Publish Date: 6/9/2013
Description: Clean up large bindings by defining them elswehere and applying them with a custom binding.

The problem:

Some view bindings can get pretty gnarly and you get no syntax support typing away inside an attribute value.

Clean View Bindings gives several great examples.

Here is another simple one that my work buddy originally coded up when showing me custom bindings..

The Html

The Script....

The Css

Comments (2):

Name: Allen Rice
Comment Date: 6/10/2013
Nice man, good write up! Good job on keeping the binding definition (myBindingDefinition) out of the viewModel. I'd be interested to see a larger scale example of something with methods etc.

Name: Allan Chadwick
Comment Date: 6/16/2013
Okay.. I gave it a computed and css switching... I got busted on this in the computed for longer than I wanted to. All good now though.

Leave a Comment:

    Captcha Challenge