【问题标题】:Knockout select binding - Add Title淘汰赛选择绑定 - 添加标题
【发布时间】:2014-06-04 12:38:40
【问题描述】:

我正在使用以下代码来设置选择列表 - 我需要为每个项目添加一个标题。这可能吗?

<select tabindex="-1" name="myDropDown" data-bind="
                visible: isVisible,
                options: $parent.myList,
                optionsText: 'name',
                optionsCaption: '- Select an item-',
                value: selectedItem,
                resizeOuter: true"></select>

【问题讨论】:

标签: select knockout.js binding


【解决方案1】:

您可以通过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"},   
             ]);

【讨论】:

    猜你喜欢
    • 2013-05-04
    • 2018-08-06
    • 2014-09-18
    • 2013-07-15
    • 2013-06-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多