Documente Academic
Documente Profesional
Documente Cultură
ViewModel
This is the data which is
linked to the user interface
Model View
This is the This is the HTML
native data and JavaScript
which make up
stored by your
your UI..
application.
Model
1. The model represents the actual
data and/or information we are
dealing with.
2. The key with the model is that it
holds the information, but not
behaviors or services that
manipulate the information
3. Model is not responsible for
formatting text to look pretty on the
screen, or fetching a list of items
from a remote server
View
1. It is the presentation of the data
which end user really interacts
with.
2. The view manages input such as
key presses, mouse movements
etc., which ultimately manipulates
properties of the model.
3. The view in MVVM contains
behaviors, events, and data-
bindings that ultimately require
knowledge of the underlying
model and viewmodel.
ViewModel
1. ViewModel acts as mediator
between View and Model
2. The model simply holds the data,
the view simply holds the formatted
data , and the controller acts as the
communicator between the two.
3. The controller might take input from
the view and place it on the model,
or it might interact with a service to
retrieve the model, then translate
properties and place it on the view.
Model, View, ViewModel (MVVM)
• Observables
• Bindings
var myViewModel = {
personName: 'Bob',
personAge: 123
};
Observables
Question: How can KO know when parts of your view
model change?
function AppViewModel() {
this.firstName = ko.observable('Bob');
this.lastName = ko.observable('Smith');
this.fullName = ko.computed(function() {
return this.firstName() + " " + this.lastName();
}, this);
}
Observable Arrays