title: Check "Select all" checkbox onload using Knockout
body: <p>I have a set of Checkboxes and a Select All checkbox implemented in the following way using Knockout. I need the "Select All" checkbox to be checked by default on page load.</p>
  
  <pre><code>$(document).ready(function(){
      viewModel=new model(ko,$);
      ko.applyBindings(viewModel);
  });
  
  function model(ko,$){
       var jsonResponse= $.parseJSON(response);
  
       this.factors=ko.observableArray(jsonResponse["factors"]);
      this.selectedFactors=ko.observableArray();
  
       this.selectAll = ko.dependentObservable({
          read: function() {
              return this.selectedFactors().length === this.factors().length;
          },
          write: function(newValue) {
              this.selectedFactors(this.selectedFactors().length === this.factors().length ? [] : this.factors().slice(0));
          },
          owner: this 
      });
  </code></pre>
  
  <p>}</p>
  
  <p>HTML:</p>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;input type="checkbox" id="selectAll" data-bind="checked: selectAll" /&gt;Select All&lt;/td&gt;
     &lt;/tr&gt;
  &lt;/table&gt;
  &lt;table data-bind="foreach: factorsSplitJsonArray"&gt;
      &lt;tr data-bind="foreach: $data"&gt;
          &lt;td&gt;
              &lt;!-- ko if: $data.hasOwnProperty("factorCode") --&gt;
              &lt;input type="checkbox" class="jqFactors" id="jqFactors" data-bind="checkedValue: $data, checked: $root.selectedFactors" /&gt; 
              &lt;span data-bind="text: factorDescription"&gt;&lt;/span&gt; 
              &lt;!-- /ko --&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>When I select or deselect any checkbox or the SelectAll checkbox the observableArray ie selectedFactors get changed. Now I need the "Select All" checkbox to be selected by default on page load and the selectedFactors should also have all the selected factors in it.</p>
  
  <p>I am new to Knockout and unable to find out how to implement this using Knockout. What if we somehow call the function selectAll explicitly, will it do the job? How do I call a ko.dependentObservable function. Can some one please help me.</p>