I'm trying to set options on a selectbox with an observable array. I can get the options to populate but the array is appearing as one option and has no value too now that I look at it.
Here's the fiddle and code below:
var Model = function (properties) {
this.AvailableLenders = ko.observableArray();
this.ModifyLenders = function (newProperties) {
var lenders = [],
count = 0;
ko.utils.arrayForEach(newProperties || properties, function (item) {
var lender = item.Lender;
if (lender) {
if (lenders.indexOf(lender) == -1) {
lenders[count] = lender;
count++;
}
}
});
this.AvailableLenders.removeAll();
return this.AvailableLenders.push(lenders.sort());
};
this.ModifyLenders();
};
ko.applyBindings(new Model([{Lender: "ASB"}, {Lender: "ANZ"}]));
HTML:
<select multiple="multiple" name="Lender" id="Lender" data-bind="options: AvailableLenders, optionsCaption: 'Please select a lender'"></select>