-
Book Overview & Buying
-
Table Of Contents
MASTERING KNOCKOUTJS
By :
Binding handler preprocessors are attached to individual binding handlers and work by modifying the binding string. They only apply to nodes of their respective handler.
Node preprocessors, on the other hand, are called on every DOM node. They run when the UI is first bound and when it is modified by bindings such as foreach or template.
The purpose of a node preprocessor is to modify the DOM before data-binding occurs, as opposed to a binding preprocessor that only modifies the data-bind attribute. A node preprocessor is defined by adding a preprocessNode function to the binding provider:
ko.bindingProvider.instance.preprocessNode = function(node) {
/* DOM code */
}A preprocessor is called once for each node. If no changes need to be made, it should return nothing. Otherwise, it can use the standard DOM API to insert new nodes or remove the current node:
node.parentNode.insertBefore(newNode, node);
Change the font size
Change margin width
Change background colour