如何从“可观察的淘汰赛"中获取选定项目的文本? [英] How can I get the text of a selected item from a Knockout Observable?

查看:55
本文介绍了如何从“可观察的淘汰赛"中获取选定项目的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以看到为获取所选项目的文本值而提供的所有Knockout方式,但仅当它是使用其中一个或两个生成的时才如此:

I can see all the Knockout-ish ways provided for getting the textual value of a selected item but ONLY if it is generated with either or both:

  1. 无值属性
  2. 或者您为选项"提供数组

但是,我自己不是在加载options数组,我只是在尝试观察下拉列表中的选定项目并检查文本表示形式.不幸的是,在这种情况下,返回的值始终是所选项目的值"属性.

However, I am not loading the options array myself, I am simply trying to observe the selected item in a drop down list and check for the textual representation. Unfortunately, it this situation, the value returned is always the "value" attribute on a selected item.

我必须在可观察的物体上执行以下操作:

I have to do something like the following on an observable:

this.selectedText = $("#myId: option:selected).text();

我敢肯定,有一种方法可以使它坚持下去.

I am sure there is a way I can get it sticking with Knockout.

我只想获取所选项目的文本值,而我没有提供选择列表的数组,并且选择列表保留了值属性.

I just want to get the textual value of a selected item where I didn't provide the array of the selection list and the selection list retains value attributes.

  <option value="2129">SomeText</option>

编辑

要想更具体地了解我为什么要这样做-选择项的值是一个ID-如果进行了某个选择,我需要能够触发一段代码可见.不幸的是,我无法绑定选择(值)的ID,因为它在开发中可能并不相同,但文本始终是相同的.

To add more concrete understanding of why I want to do that is - the value for the selection item is an ID - I need to be able to trigger a section of code to be visible if a certain selection is made. Unfortunately, I can't bind to the id of the selection (value) as it might not be the same for development, but the text will always be the same.

推荐答案

我认为我们必须绑定到可观察数组以使下拉列表中的下拉列表中可观察的文档也不会列出其他内容

I think we have to bind to observable array to make drop down list obserevable documentation at knockout also does not list something else

http://knockoutjs.com/documentation/options-binding.html

这篇关于如何从“可观察的淘汰赛"中获取选定项目的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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