I Have to add a dropdown dynamically on a button click. I'm trying to update the array but it is not showing the values in dropdown
<a data-bind='click:addBillItem'>Add</a>
My View Model is given below:
function AssignmentViewModel() {
self.billDescriptions = ko.observableArray();
this.addBillItem = function() {
var = '<select id="ddlBillItemDescription" data-bind="';
html += 'options:billDescriptions,';
html += 'optionsText:"ItemName",';
html += 'optionsCaption: "Select Bill Description",';
html += 'optionsValue:"ItemName",';
html += 'value:BillItemDescription';
html += '</select>';
$("#dropdown").append(html);
self.billDescriptions(billItemDescriptions);
var billItemDescriptions = GetBillItemDescriptions();
self.billDescriptions(billItemDescriptions);
};
}
ko.applyBindings(new AssignmentViewModel());
jQueryDOM manipulation is not the ideal "knockout" way, you can usually achieve a desired behavior strictly through a combination of bindings.