O'Reilly logo

Getting Started with Knockout.js for .NET Developers by Andrey Akinshin

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Custom bindings

In Chapter 2, Creating a Simple Knockout.js Application, we examined a variety of standard Knockout.js bindings such as text, visible, click, submit, and so on. However, in a big application, this list may not be enough. Fortunately, you can define your own custom bindings.

Registering a new binding

Knockout.js provides us with the ko.bindingHandlers property to register new bindings. You can define a new subproperty of it as a JavaScript object with two callback properties: init and update. Let's take a look at the short binding registration template:

ko.bindingHandlers.newBindingName = { init: function(element, valueAccessor, allBindings) { // Called on first binding applying to an element // Set up any initial state }, update: ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required