由
khcyt 的个人资料给出的答案
<zk> <zscript>
class A
{
public A(String s, Long v, Boolean is_group) { s_= s; v_= v; is_group_= is_group; }
public String getLabel() { return s_; }
public void setLabel(String s) { s_=s; }
public Boolean isGroup() { return is_group_; }
public Long getValue() { return v_; }
public String getPlaceholder() { return "Please type some text"; }
String s_= null;
Long v_= null;
Boolean is_group_= null;
}
lm.add(new A("Today", 1L, Boolean.TRUE));
lm.add(new A("RE: Bandbox Autocomplete Problem", 2L, Boolean.FALSE));
lm.add(new A("", 3L, Boolean.FALSE));
lm.add(new A("RE: FileUpload", 4L, Boolean.FALSE));
lm.add(new A("", 5L, Boolean.FALSE));
lm.add(new A("Yesterday", 10L, Boolean.TRUE));
lm.add(new A("", 11L, Boolean.FALSE));
lm.add(new A("RE: SelectedItemConverter Question' ite", 12L, Boolean.FALSE));
lm.add(new A("Last week", 100L, Boolean.TRUE));
lm.add(new A("RE: Times_Series Chart help", 101L, Boolean.FALSE));
lm.add(new A("", 102L, Boolean.FALSE));
class VM
{
public ListModel getListModel() { return lm; }
}
]]></zscript>
<window id="win" title="Window ZK6 dynamic template" border="normal" width="600px"
apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('VM')" >
<listbox model="@bind(vm.listModel) @template(each.isGroup() ? 'group_model' : 'item_model')">
<listhead>
<listheader hflex="3" label="Column 1"/>
<listheader hflex="1" label="Column 2"/>
</listhead>
<template name="group_model">
<listgroup open="true" label="@load(each.label)"/>
</template>
<template name="item_model">
<listitem vflex="1">
<listcell>
<textbox hflex="1" placeholder="@init(each.placeholder)" value="@bind(each.label)"/>
</listcell>
<listcell>
<label value="@load(each.value)"/>
</listcell>
</listitem>
</template>
</listbox>
</window>
</zk>