-
Book Overview & Buying
-
Table Of Contents
MASTERING KNOCKOUTJS
By :
So far, we have looked at two properties of binding handlers: the init and update functions. Binding handlers have another optional function, which is preprocess, that is run before the init function. A preprocessor's purpose is to modify the data-binding attribute before Knockout determines what bindings are to be applied.
Preprocessors don't deal with elements or binding contexts; they just deal with the strings that the binding will evaluate. For example, if we had a preprocessor that converts all text bindings to uppercase, then the following span element will be processed:
<span data-bind="text: 'That Guy'"></span>
This span element would be processed as if it was written like this:
<span data-bind="text: 'That Guy'.toUpperCase()"></span>
If you were to inspect the HTML after this, you will still see the original data-bind attribute. This is because preprocessors don't actually...
Change the font size
Change margin width
Change background colour