I've seen similar topics about it, but none of them using exactly the same structure as me.
I am using multiple view models and I deal with it by creating a MasterModel function which later on I pass as an argument to applyBindings
.
Basically something like this:
var MasterModel = function(){
this.user = new UserViewModel();
this.department = new DepartmentViewModel();
}
ko.applyBindings(MasterModel);
Now, I would like to be able to access from Javascript to a function inside one of my view models and I'm having troubles with it.
I managed to call the viewmodel function if I change the applyBindings
to this:
var mm = new MasterModel();
ko.applyBindings(mm);
mm.user.sayHi();
But then I found out things like the following stop working:
<ul data-bind="foreach: department.list()">
<li data-bind="text: department.getDemo($data)"></li>
</ul>
Message: department is not defined
And as you can see here, it works perfectly when using ko.applyBindings(MasterModel);
Any solution for this?