title: KnockoutJS: dynamically populate dropdownlist
body: <p>I am very newbie to KnockoutJS,I have done the simple things with dropdownlist, populating and using static data but now need to perform two things dropdownlist dynamically</p>
  
  <p>1.Want to populate dropdownlist dynamically (say any list), this list we can get from my controller.</p>
  
  <pre><code>        var InsertVal = function(name, id) {
              this.pname = name;
              this.pid = id;
              };
  
              var Valuess = function() {
              $.ajax({
              dataType: "json",
              url: "getParentCategory.do",
              success: function (data) {
              for(i=0;i&lt;data.length;i++){
  totalval.push(new InsertVal(data[i].parentCategoryName,data[i].parentCategoryId));
                  }           
                  handledata(totalval);
              }
                });   
  
                    };
          var handledata= function(totalval){
          console.log("!!@#"+totalval);
          return totalval;
      }
  
  
  
          var obj={
          parentCategory : ko.observableArray(Valuess()),
          chosenParentCategory : ko.observableArray()
          };
  
          ko.applyBindings(obj);
  
  
               &lt;p&gt;
               &lt;select data-bind="options: parentCategory,
                optionsText: 'pname',
              value: chosenParentCategory,
              optionsCaption: 'Choose...'"&gt;
               &lt;/select&gt;                
                                 &lt;/p&gt;
  
                  &lt;div data-bind="visible: chosenParentCategory"&gt;
                    You have chosen a Parent Category
                  &lt;span data-bind="text: chosenParentCategory() ?
   chosenParentCategory().pid : '0'"&gt;&lt;/span&gt;.
                   &lt;/div&gt;
  </code></pre>
  
  <p>Trying to populate the dropdownlist dynamically, getting json data from controller successfully but data not getting populated.</p>