Knockout (web framework)
Knockout is a standalone JavaScript implementation of the Model–View–ViewModel pattern with templates. The underlying principles are therefore:
- a clear separation between domain data, view components and data to be displayed
- the presence of a clearly defined layer of specialized code to manage the relationships between the view components
These features streamline and simplify the specification of complex relationships between view components, which in turn make the display more responsive and the user experience richer.
Knockout was developed and is maintained as an open source project by Steve Sanderson.
Features
Knockout includes the following features:- Declarative bindings
- Automatic UI refresh
- Dependency tracking Templating
Examples
View Model (JavaScript)
function ViewModel
ko.applyBindings);
2. Creating Custom Binding Handlers in KnockoutJS
Use the ko.bindingHandlers object to specify your custom binding’s name and create an init or update function when creating a custom binding handler. The init function is called when the binding has been applied to an element, perfect for onetime initialization. Whenever the bound observable changes, an update function is called that allows you to react to changing data.
Here’s a simple example of a custom binding handler that applies a jQuery UI datepicker to an input element:
Custom Binding Handler
ko.bindingHandlers.datepicker = ;