javascript 剑道 combobox.value(x) 无法正常工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12748024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Kendo combobox.value(x) not working correctly
提问by andree
I'm trying to set value of kendo combobox dynamically, but when trying like:
我正在尝试动态设置剑道组合框的值,但是在尝试时:
var lvl1 = $("#level1Id").data("kendoComboBox");
var lvl2 = $("#level2Id").data("kendoComboBox");
var l2value = lvl2.value(); // save value for later use
... // do something that includes changing lvl2.value
lvl2.value(l2value.toString()); // set lvl2.value back to previous
the combobox value sets to "Code" field - for example - 2, instead of "Value/Text" field - "corresponding value of l2value code". I understand, that value(x) takes string parameter, so I've tried different conversion methods (int->string), but no luck. Am I missing something here? Setting this combobox value dynamically is essential for me, so any help would be appreciated.
组合框值设置为“代码”字段 - 例如 - 2,而不是“值/文本”字段 - “l2value 代码的对应值”。我明白, value(x) 需要字符串参数,所以我尝试了不同的转换方法(int->string),但没有运气。我在这里错过了什么吗?动态设置这个组合框值对我来说是必不可少的,所以任何帮助将不胜感激。
EDIT: I'm changing the combobox filter just before setting value the second time. Could that be the reason here?
编辑:我正在第二次设置值之前更改组合框过滤器。这可能是这里的原因吗?
回答by pvanhouten
Take a look at this fiddle: http://jsfiddle.net/pvanhouten/qb8rD/1/. I tried to show how you can get both the currently selected text (apple) and the selected value (1). You can also type a value into the text input to set the selected value of the combo box. If you type in apple
, it will select the apple
entry from the combo box. If you type in something that isn't in the combo box list, it will set the value of the combo box to that value and both the id and text for the currently selected item will be the value that you type in. Does that help at all?
看看这个小提琴:http: //jsfiddle.net/pvanhouten/qb8rD/1/。我试图展示如何获取当前选定的文本 (apple) 和选定的值 (1)。您还可以在文本输入中键入一个值以设置组合框的选定值。如果您输入apple
,它将apple
从组合框中选择条目。如果您输入的内容不在组合框列表中,它会将组合框的值设置为该值,当前所选项目的 id 和文本都将是您输入的值。这有帮助吗根本?