title: What is best way to bind a Kendo UI dropdownlist to a ViewModel that is populated by a datasource?
body: <p>I have a kendoUI dropdownlist that is in a template and is bound to a ViewModel, along with a span that is bound to the data item that is selected in the dropdownlist:</p>
  
  <pre><code>&lt;p&gt;
      &lt;label&gt;Appointment Type: &lt;/label&gt;
      &lt;select id="appointmentTypeDropDownList"
              data-text-field="Name"
              data-value-field="AppointmentTypeId"
              data-role="dropdownlist"
              data-bind="source:appointmentTypes, value:AppointmentTypeId"
              data-autobind="true"
              data-select="onSelected" /&gt;
  &lt;/p&gt;
  &lt;p&gt;&lt;label&gt;Duration:&lt;/label&gt;
      &lt;span data-bind="text:selectedAppointment.Duration"&gt;&lt;/span&gt; minutes
  &lt;/p&gt;
  </code></pre>
  
  <p>My ViewModel:</p>
  
  <pre><code>var viewModel = new kendo.observable({
      appointmentTypes: appointmentTypesDataSource,
      selectedAppointment : null,
  });
  </code></pre>
  
  <p>Originally, I was using a hardcoded array of appointmentTypes, and setting the selectedAppointment to appointmentTypes[0] in the above viewModel declaration.  That doesn't work now, because the datasource loads asynchronously.  The viewModel is updated in the onSelected function:</p>
  
  <pre><code>var onSelected = function (e) {
      var dataItem = this.dataItem(e.item.index());
      viewModel.set("selectedAppointment", dataItem);
  };
  </code></pre>
  
  <p>The template is in a window, and the span is empty the first time it loads, and then works thereafter (once the data has loaded from the first request).</p>
  
  <p>My question is, how can I get the data binding of the span to work on the first request, so that it will display the Duration of the currently selected appointmentType from the list that is returned by the data source?  Do I try and bind it to the selected data item of the dropdownlist?  Is there a callback somewhere I should be using to do this?  The template is inside of a kendoScheduler, if that matters:</p>
  
  <pre><code>var template = kendo.template($("#editor").html());
  
  $("#scheduler").kendoScheduler({
      editable: {
          template: template()
      }
  });
  </code></pre>
  
  <p>Thanks!</p>
  
  <p><strong>Update</strong>: The template I've been working with is an editor for a Kendo UI Scheduler, which was not bound to its viewmodel, but was using part of the viewmodel for its datasource.  In this case, trying to use the data-bind="events:{...}" syntax was causing the weird type errors I was getting.  To wire up the databound event, Atanas let me know to use data-bound="onDataBound" and a global handler function (or alternately to configure my scheduler declaratively and bind it to the viewmodel).  Using data-bound combined with the answer(s) below worked for me.</p>