在淘汰赛中获得选定的选项文本 [英] get selected option text in knockout

查看:23
本文介绍了在淘汰赛中获得选定的选项文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用knockoutjs 来绑定一个选择列表.这是一个示例,我想获得选定的选项文本而不是选定的值.

I am using knockoutjs to bind a select list. Here is a Sample , I want to get selected option text instead of selected value.

如何使用knockoutjs获得它?

How to get it using knockoutjs ?

<select id="projectMenu" name="projectMenu" data-bind="   
        value: selectedProject,
        options:        projectFilters,
        optionsText:    'a', 
        optionsValue:   'b',   
        optionsCaption: '-- Select Project --'
    ">
    </select>
<b>Selected Project:</b> <span data-bind="text: selectedProject"></span>

推荐答案

最简单的方法是移除 optionsValue 绑定.如果不指定 optionsValue 绑定,则整个项目将是选定的值.

The simplest way to do it is to remove the optionsValue binding. When you don't sepcify the optionsValue binding, the entire item will be the selected value.

<select id="projectMenu" name="projectMenu" data-bind="   
        value: selectedProject,
        options:        projectFilters,
        optionsText:    'a',         
        optionsCaption: '-- Select Project --'
    ">
    </select>
<b>Selected Project:
<span data-bind="text: selectedProject() ? selectedProject().a : 'no selection '"></span>

看小提琴

这篇关于在淘汰赛中获得选定的选项文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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