Kendo combobox.value(x) not working correctly

不羁的心 提交于 2020-01-06 04:00:10

问题


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.

EDIT: I'm changing the combobox filter just before setting value the second time. Could that be the reason here?


回答1:


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?



来源:https://stackoverflow.com/questions/12748024/kendo-combobox-valuex-not-working-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!