In the MVVM template implemented by JavaScript, often the "Model" part is provided by the web api. The data that is provided on the page is a model. Now, whether this data is in a separate model object as soon as it is in JavaScript is a different story.
Often a view model is simply a model complemented by properties and functions to support the particular view to which it is applied. Client-side calculations, outlier control values, client-side verification procedures, etc. In this case, the view model may look like this:
var vm = { save: function(){ save logic... }, cancel: function(){ cancel logic... }, states: ko.observable(),
In other cases, the model will be stored in a separate object . In this case, the view model might look like this:
var customerModel = getCustomerFromDataSource(); var vm = { save: function(){ save logic... }, cancel: function(){ cancel logic... }, states: ko.observable(),
The main thing to keep in mind is that the model is data, and the View model is the layer that makes your model viewable (usually using data binding). Sometimes a Model can be a separate class; in other cases, the model is only a known set of properties in the view model.
source share