What is "knockoutjs"
The principles behind Knockoutjs are:
- Clear separation between the data domain, interface components and the data that will be displayed.
- The presence of a clearly defined layer of specialized code to manage the relationships between interface components.
Key features
- Elegant dependency tracking - Automatic updating of parts of your interface whenever your data model changes.
- Declarative Links - Simple and obvious way to connect parts of your interface with your data model. You can easily create complex dynamic interfaces using arbitrarily nested link contexts.
- Trivially extensible - Implement custom behaviors like new declarative links for easy reuse, with few lines of code.
Additional features
- Pure Javascript - Integrates with any server or any technology client-side
- Can be added on top of any application Web existing without requiring major architectural changes
- Compact - Approximately 13 kB after compression gzip
- Works on any of the browser best known (IE 6+, Firefox 2+, Chrome, Safari and others)
- Comprehensive set of specifications (developed in the BDD style) means that the correct functioning can be easily checked in the new Browsers and platforms.
Example of use
HTML
<p>First name: <input data-bind="value: firstName" /></p>
<p>Last name: <input data-bind="value: lastName" /></p>
Javascript (View Model)
function ViewModel() {
this.firstName = ko.observable("Joe");
this.lastName = ko.observable("Bloggs");
this.fullName = ko.computed(function() {
return this.firstName() + " " + this.lastName();
}, this);
}
ko.applyBindings(new ViewModel());