【问题标题】:Knockoutjs : How to add title to options in selectKnockoutjs:如何为选择中的选项添加标题
【发布时间】:2012-09-25 20:28:21
【问题描述】:

我使用 Knockoutjs 选项绑定来填充我的选择

<select data-bind="value: val, options: options, optionsText: 'text', optionsValue: 'ID'">
</select>

但对于某些选项,文本是相同的。然后我想添加一个title属性来添加信息。我可以在不修改 knockoutjs 本身的情况下使用 knockout 来做到这一点吗?

可能在 optionsText 中使用了一个函数,但我看不到如何

【问题讨论】:

  • “添加标题”属性是什么意思?那会是什么样子?
  • 类似于

标签: drop-down-menu attributes knockout.js


【解决方案1】:

您可以使用 foreach 绑定来实现,如下所示:

<select data-bind="foreach: options, value: selectedValue">
    <option data-bind="value: ID, text: text, attr: {title: title}" ></option>
</select>

Here 是一个工作示例。

【讨论】:

    猜你喜欢
    • 2022-09-28
    • 1970-01-01
    • 1970-01-01
    • 2019-02-08
    • 2012-05-19
    • 1970-01-01
    • 2014-12-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多