我正在尝试在带有可观察数组的选择框上设置选项。我可以获得要填充的选项,但是该数组显示为一个选项,并且现在我查看它也没有任何价值。
这是下面的小提琴和代码:
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>