我试图在组合框中获取选定的值,但它返回为ComboItem。如何将值作为字符串获取?
<zscript>
<![CDATA[
String[] months = { "Ada", "Basic", "C", "C++", "Cobol", "Forth",
"Fortran", "Go", "Groovy", "Haskell", "Java", "JavaScript", "Lisp",
"Python", "Ruby", "Scala", "Scheme" };
ListModel lmonths = new SimpleListModel(months);
]]></zscript>
<combobox id="searchCombo"
forward="onChange=onSearch" model="@{months}" >
<!--
<comboitem self="@{each='months'}"
label="@{months}" value="@{months}">
</comboitem>
-->
</combobox>
这是我的onSearch方法
public void onSearch(ForwardEvent event) {
System.out.println(searchCombo.getSelectedItem());
prodevt.search(searchCombo.getSelectedItem().toString());
filterCbox.setChecked(true);
AnnotateDataBinder binder = (AnnotateDataBinder) win.getVariable(
"binder", true);
binder.loadAll();
}
答案 0 :(得分:3)
我像
一样解决了它searchCombo.getSelectedItem().getValue().toString();
答案 1 :(得分:2)
ZK与组合框的数据绑定非常强大,
我创建了一个样本来同步组合框和列表框中的选择数据
<?page title="new page title" contentType="text/html;charset=UTF-8"?>
<?init class="org.zkoss.zkplus.databind.AnnotateDataBinderInit" ?>
<zk>
<zscript>
<![CDATA[
String[] langs = { "ZK" ,"Ada", "Basic", "C", "C++", "Cobol", "Forth",
"Fortran", "Go", "Groovy", "Haskell", "Java",
"JavaScript","Lisp", "Python", "Ruby", "Scala",
"Scheme"
};
//(Optional) Default Select ZK
String things_i_have_selected = langs[0];
]]></zscript>
<hlayout>
<combobox model="@{langs}" selectedItem="@{things_i_have_selected}" />
<combobox model="@{langs}" selectedItem="@{things_i_have_selected}" />
<listbox model="@{langs}" selectedItem="@{things_i_have_selected}"
rows="5" width="400px">
<listitem self="@{each=String}">
<listcell label="@{String}"></listcell>
</listitem>
</listbox>
</hlayout>
</zk>
我想说的是你不需要获得选择项的值:)
参考
答案 2 :(得分:1)
searchCombo.getSelectedItem()。getValue() - &gt;获取所选ComboItem的值
searchCombo.getSelectedItem()。getLabel() - &gt;获取所选ComboItem的文本