I'm working with Teleriks Kendo UI in hope it makes my life easier (not proved yet). Currently I implemented a kendoui dropdownlist (#gamelist) filled up by a JSON php script. That works so fine so far…. I would like now to change (not set) a text of an option inside this dropdownlist (I know the value from outside the dropdownlist). I couldn't find anything about changing values and/or text of an option entry at Teleriks example page: http://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist
我正在与Teleriks Kendo UI合作,希望它让我的生活更轻松(尚未证明)。目前我实现了一个由JSON php脚本填充的kendoui下拉列表(#gamelist)。到目前为止工作得很好......我现在想要更改(未设置)此下拉列表中的选项文本(我知道下拉列表外部的值)。我在Teleriks示例页面上找不到有关更改选项条目的值和/或文本的任何信息:http://docs.telerik.com/kendo-ui/api/javascript/ui/dropdownlist
I am so far that I can't f.e. display the text with JQuery directly:
我到目前为止我无法做到。直接使用JQuery显示文本:
alert($("#gamelist option:selected").text());
-> empty message box
- >空消息框
Instead of that I have to do it that way on KendoUI side:
而不是我必须在KendoUI方面这样做:
var dropdownlist = $("#gamelist").data("kendoDropDownList");
alert(dropdownlist.text());
-> Display the current selected entry in dropdownlist
- >在下拉列表中显示当前选定的条目
So I am not allowed to change a text of an option like:
所以我不允许更改选项的文本,例如:
$('#gamelist option[value=37]').text('Chess');
Sounds easy directly with JQuery but doesn't work on Teleriks side. How can I change text inside a dropdownlist in KendoUI? Anyone knows?
使用JQuery直接听起来很容易,但在Teleriks方面不起作用。如何在KendoUI中的下拉列表中更改文本?有谁知道?
1 个解决方案
#1
After deeper search I could fiddle out the solution. How to change a (specific) option text inside Kendo UI option list:
经过深入搜索后,我可以找出解决方案。如何更改Kendo UI选项列表中的(特定)选项文本:
var dropdownlist = $("#gamelist").data("kendoDropDownList");
dropdownlist.dataItem().title = '<desired_text>';
dropdownlist.refresh();
This will change the option text of the current displayed entry. If you want to change the text of another option you can pass the index value (starting at 0) on dataItem(). The refresh() is important to show up the changed text.
这将更改当前显示条目的选项文本。如果要更改另一个选项的文本,可以在dataItem()上传递索引值(从0开始)。 refresh()对于显示已更改的文本非常重要。
#1
After deeper search I could fiddle out the solution. How to change a (specific) option text inside Kendo UI option list:
经过深入搜索后,我可以找出解决方案。如何更改Kendo UI选项列表中的(特定)选项文本:
var dropdownlist = $("#gamelist").data("kendoDropDownList");
dropdownlist.dataItem().title = '<desired_text>';
dropdownlist.refresh();
This will change the option text of the current displayed entry. If you want to change the text of another option you can pass the index value (starting at 0) on dataItem(). The refresh() is important to show up the changed text.
这将更改当前显示条目的选项文本。如果要更改另一个选项的文本,可以在dataItem()上传递索引值(从0开始)。 refresh()对于显示已更改的文本非常重要。