Features
- Model-View-ViewModel (MVVM) Framework
- Subscribable and Observable objects
- Library includes templating
- Intuitive data binding methodology.
Pros
- Usage - Easy
- Learning Curve - Easy
- Very Good API Documentation
- Nice tutorials and startup guide.
- Pseudo re-usable components via templates.
- No other dependency
When to use Knockout?
- Single page applications (SPA).
- Small to medium complexity projcts.
- If you dont intend to include other dependencies.
function () {
var self = this;
self.dataok = ko.observable(true);
self.datanotok = ko.observable(false);
self.validate = function() {
if (self.persons.firstName() == null || self.persons.firstName() == ""
|| self.persons.lastName() == "" || self.persons.lastName() == null) {
self.datanotok(true);
self.dataok(false)
}
else {
self.dataok(true);
self.datanotok(false);
}
};
self.persons = new ;
}
function (fname,lname) {
var self = this;
self.firstName = ko.observable(fname);
self.lastName = ko.observable(lname);
console.log(self.firstName);
self.fullName = ko.computed(function(){
return self.firstName() + ' ' + self.lastName();
});
}
ko.applyBindings(new ());