title: Call function from outside master view model in knockout.js
body: <p>I've seen <a href="https://stackoverflow.com/questions/10643940/knockout-js-access-viewmodel-in-javascript-function-outside-viewmodels-scope">similar</a> <a href="https://stackoverflow.com/questions/26047660/calling-function-in-knockout-js-from-outside-view-model">topics</a> about it, but none of them using exactly the same structure as me.</p>
  
  <p>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 <code>applyBindings</code>.</p>
  
  <p>Basically something like this:</p>
  
  <pre><code>var MasterModel = function(){
      this.user = new UserViewModel();
      this.department = new DepartmentViewModel();
  }
  
  ko.applyBindings(MasterModel);
  </code></pre>
  
  <p>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.</p>
  
  <p>I managed to call the viewmodel function if I change the <code>applyBindings</code> to this:</p>
  
  <pre><code>var mm = new MasterModel();
  ko.applyBindings(mm);
  
  mm.user.sayHi();
  </code></pre>
  
  <p>But then I found out things like the following stop working:</p>
  
  <pre><code>&lt;ul data-bind="foreach: department.list()"&gt;
       &lt;li data-bind="text: department.getDemo($data)"&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <blockquote>
    <p>Message: department is not defined</p>
  </blockquote>
  
  <p><a href="http://jsfiddle.net/imac/qWmat/107/" rel="nofollow noreferrer">Reproduction online</a></p>
  
  <p>And as you can see <a href="http://jsfiddle.net/imac/qWmat/108/" rel="nofollow noreferrer">here</a>, it works perfectly when using <code>ko.applyBindings(MasterModel);</code></p>
  
  <p>Any solution for this?</p>