Knockoutjs:如何在选择中添加选项的标题 [英] Knockoutjs : How to add title to options in select

查看:121
本文介绍了Knockoutjs:如何在选择中添加选项的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use Knockoutjs options binding to populate my selects as this

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

但是对于某些选项,文本是一样的。然后我想添加一个title属性来添加信息。我可以在没有修改knockoutjs的情况下进行淘汰吗?

But for some option, the text is the same. Then I would like to add a title attribute to add information. Can I do that with knockout without modifying knockoutjs itself ?

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

May be using a function in optionsText, but I can't see How

推荐答案

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

You can do it using the foreach binding, like this:

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

这里是一个工作示例。

这篇关于Knockoutjs:如何在选择中添加选项的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆