Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 2nd, 2012  |  syntax: None  |  size: 1.00 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. KnockoutJs Observable Arrays and Dropdownlists
  2. <script type="text/javascript">
  3.     $(document).ready(function () {
  4.         var sampleSubmission = function () {
  5.             this.selectedPlatform = ko.observable();
  6.             this.platforms = ko.observableArray();
  7.  
  8.             this.showSearch = ko.observable(false);
  9.             this.craftText = ko.observable();
  10.             this.showSerialNumber = ko.observable(0);
  11.  
  12.             this.selectedPlatform.subscribe(function (platformId) {
  13.  
  14.  
  15.  
  16.  
  17.  
  18.             } .bind(this));
  19.         };
  20.  
  21.         var sampleSubmissionViewModel = new sampleSubmission();
  22.         ko.applyBindings(sampleSubmissionViewModel);
  23.  
  24.         //Load the platforms
  25.         $.ajax({
  26.             url: '@Url.Action("GetPlatforms", "Home")',
  27.             type: 'GET',
  28.             success: function (data) {
  29.                 sampleSubmissionViewModel.platforms(data);
  30.             }
  31.         });
  32.     });  
  33.  
  34. </script>
  35.        
  36. <select data-bind="options: platforms, value: selectedPlatform, optionsText: 'name'"></select>