我正在使用以下代码设置选择列表 - 我需要为每个项目添加标题。这可能吗?
<select tabindex="-1" name="myDropDown" data-bind="
visible: isVisible,
options: $parent.myList,
optionsText: 'name',
optionsCaption: '- Select an item-',
value: selectedItem,
resizeOuter: true"></select>
答案 0 :(得分:0)
您可以使用foreach
绑定实现此目的,例如:
<select tabindex="-1" name="myDropDown" data-bind="foreach: $parent.myList, value: selectedItem, visible: isVisible, resizeOuter: true">
<option data-bind="value: myListValue, text: myListText, attr: {title: myListTitle}" ></option>
</select>
self.myList= ko.observableArray([
{myListText: "first", myListValue: 1, myListTitle: "the first"},
{myListText: "second", myListValue: 2, myListTitle: "the second"},
]);