blog tag

Knockout Generic Binding

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

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
Allen Rice (06/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.


Allan Chadwick (06/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.


© Chadwick 2021