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

查看:273
本文介绍了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天全站免登陆