I've seen there's generally a bit of confusion when talking about multiple view models in knockout.js
The ko documentation doesn't really explain very much how to deal with multiple view models, how to communicate between them or when should they be considered.
I found this site explaining different ways of creating multiple view models and how to interact with them.
I gave it a try and I created a master model with different submodels:
var MasterModel = function(){
this.orders = new ordersViewModel(),
this.dates = new datesViewModel(),
this.equipment = new equipmentViewModel();
};
After that, I found myself having to use with: nameOfModel
in many places (and create extra wrappers or HTML comments for it) or even just using the view model's name as a prefix data-bind="foreach: orders.getList()"
.
Besides that, then we have the problem of communicating between them, and although it can be solved somehow, it doesn't seem as simple as when dealing with a single view model.
My question is, is it worthy to create multiple view models? If so, when? It seems it only adds more difficulties and I do not end up seeing the advantages of it. (yeah, they say its maintains modularity... but I don't end up seeing a clear advantage )