I have a collection with x amount of Dropdowns. I would like to fill out the dropdown with the list comming from the DB.
The HTML
<div class="input-col input-col-short">
<select data-bind="options: $parent.insuranceCoverList(), optionsText: 'displayName', optionsValue: 'insuranceCoverId', value: selectedInsuranceCover"></select>
</div>
The variable "arr" is empty when I try to return it. If I return just the object with values then it works but not with the "arr" variable. And this is my insuranceCoverList()
self.insuranceCoverList = function () {
var arr = [];
// Get data from the DB
GetInsuranceCover(self.InsuranceTypeID())
.done(function (data) {
$(data).each(function (i, v) {
arr.push(new AvailableDropdownItems({ dropdownItemId: v.ProgramCode, dropdownItemName: v.DisplayValue }));
});
});
// doesn't work
return arr;
// works
//return [{ insuranceCoverId: 0, displayName: "Option A" }, { insuranceCoverId: 1, displayName: "Option B" }, { insuranceCoverId: 2, displayName: "Option C" }];
};
Any suggestions where I fail?