title: how to ensure a specific value is selected as default value in a drop downlist in knockoutjs
body: <p>What I'm trying to get is 'Another test' instead of 'test' as default value (selected when page loads) in dropdownlist.</p>
  
  <p>In simple cases <a href="http://knockoutjs.com/examples/controlTypes.html" rel="nofollow">as shown here</a> its easy.. but when you have nested structures as below.. what to do..</p>
  
  <p>My html:</p>
  
  <pre><code>  &lt;div data-bind="with:g"&gt;
  
              &lt;div&gt;&lt;input type="text" class="form-control" data-bind="value: gname" /&gt;&lt;/div&gt;
  
              &lt;div&gt;
                  &lt;table&gt;
  
                      &lt;tbody&gt;
                          &lt;tr data-bind="with:gdetails"&gt;
                              &lt;td&gt;
                                  &lt;select data-bind="options: eventschemas, optionsText: 'schema', value:eventschemacondition().schema, event: {change:eventschemacondition().setschema}"&gt;&lt;/select&gt;
  
                              &lt;/td&gt;
  
                          &lt;/tr&gt;
                      &lt;/tbody&gt;
                  &lt;/table&gt;
                  &lt;pre data-bind="text: ko.toJSON($data, null, 2)"&gt;&lt;/pre&gt;
              &lt;/div&gt;
          &lt;/div&gt; 
  </code></pre>
  
  <p>The js codebase:</p>
  
  <pre><code> var eventschemas = [{ "schema": "Test" }, { "schema": "Another Test" }];
  
          var AppScope = function () {
              function EventSchemaCondition(data) {
                  this.schema = ko.observable(data.schema);
  
  
              }
  
              function Gdetails(data) {
                  this.eventschemacondition = ko.observable(data.eventschemacondition);
              }
  
              function G(data) {
                  this.gname = ko.observable(data.gname);
                  this.gdetails = ko.observable(data.gdetails);
              }
  
              function GsViewModel() {
                  var self = this;
                  self.g = ko.observable(
                  new G({
                      gname: "",
                      gdetails: new Gdetails({ eventschemacondition: new EventSchemaCondition({ schema: "" }) })
                  }));
              }
  
              ko.applyBindings(new GsViewModel());
          }();
  </code></pre>
  
  <p><a href="http://jsfiddle.net/supercool/LkqTU/22105/" rel="nofollow">The full jsfiddle:</a></p>
  
  <p>Any help is sincerely appreciated</p>
  
  <p>Thanks</p>