-
FEATURED COMPONENTS
First time here? Check out the FAQ!
<zk> <zscript><![CDATA[ ListModel quarters = new ListModelArray(new String[] {"Q1", "Q2", "Q3", "Q4"}); Map months = new HashMap(); months.put("Q1", new ListModelArray(new String[] {"Jan", "Feb", "Mar"})); months.put("Q2", new ListModelArray(new String[] {"Apr", "May", "Jun"})); months.put("Q3", new ListModelArray(new String[] {"Jul", "Aug", "Sep"})); months.put("Q4", new ListModelArray(new String[] {"Oct", "Nov", "Dec"})); ListModel qs = (quarters); ]]></zscript> <listbox model="${quarters}"> <template name="model"> <listitem> <listcell>${each}</listcell> <listcell> <listbox model="${months}"> <template name="model"> <listitem label="${each}"/> </template> </listbox> </listcell> </listitem> </template> </listbox> </zk>
<zk> <zscript><![CDATA[ java.util.Map quarters = new java.util.TreeMap(); quarters.put("Q1", new java.util.ArrayList(java.util.Arrays.asList(new String[] {"Jan", "Feb", "Mar"}))); quarters.put("Q2", new java.util.ArrayList(java.util.Arrays.asList(new String[] {"Apr", "May", "Jun"}))); quarters.put("Q3", new java.util.ArrayList(java.util.Arrays.asList(new String[] {"Jul", "Aug", "Sep"}))); quarters.put("Q4", new java.util.ArrayList(java.util.Arrays.asList(new String[] {"Oct", "Nov", "Dec"}))); ]]></zscript> <listbox> <listitem forEach="${quarters}"> <listcell>${each.key}</listcell> <listcell> <listbox> <listitem forEach="${each.value}" label="${each}"/> </listbox> </listcell> </listitem> </listbox> </zk>
If the data is readonly (render once when loading) then using forEach is OK.
However it cannot handle dynamic data but model can.
Hi guys,
I've additional question regarding template stuff - is it possible to mixed dynamic content with static, please see example below
<zk> <zscript><![CDATA[ ListModel quarters = new ListModelArray(new String[] {"Q1", "Q2", "Q3", "Q4"}); Map months = new HashMap(); months.put("Q1", new ListModelArray(new String[] {"Jan", "Feb", "Mar"})); months.put("Q2", new ListModelArray(new String[] {"Apr", "May", "Jun"})); months.put("Q3", new ListModelArray(new String[] {"Jul", "Aug", "Sep"})); months.put("Q4", new ListModelArray(new String[] {"Oct", "Nov", "Dec"})); ListModel qs = (quarters); ]]></zscript> <listbox model="${quarters}"> <template name="model"> <listitem> <listcell>STATIC RENDERS ONCE </listcell> </listitem> <listitem> <listcell>${each}</listcell> <listcell> <listbox model="${months}"> <template name="model"> <listitem label="${each}"></listitem> </template> </listbox> </listcell> </listitem> </template> </listbox> </zk>
apply to EL rule.
<listbox model="${months}"> (at here, each is Q1/Q2..., model is a ListModelArray in months.)
and
<listitem label="${each}"></listitem> (at here, each is Jan/Feb...)
Hi Dennis,
Thanks for your reply but actually I don't get it ... anyway my above example is not consistent ...please find below updated version ...
<zk> <div apply="org.zkoss.bind.BindComposer" viewModel="@id('model') @init('foo.MyViewModel')"> <listbox children="@{model.months}"> <template name="children"> <listitem> <listcell>STATIC RENDERS ONCE </listcell> </listitem> <listitem> <listcell>${each}</listcell> </listitem> </template> </listbox> </div> </zk>
..so I'm interested in output like that:
...
STATIC RENDERS ONCE
January
February
March
April
...
hopefuly this is better example ....
kwalczak
I saw you binding syntax is not correctly,
Basically, you should use <listbox children="@load(model.months"/>
and in listcell , use <listcell label="@load(each)"/>
for the first static item, use @template and give different template
read this for example of dynamic template
http://books.zkoss.org/wiki/ZK_Developer's_Reference/MVVM/Data_Binding/Children_Binding
read this for iteration status
http://books.zkoss.org/wiki/ZK%20Developer's%20Reference/MVVM/Data%20Binding/Property%20Binding#Collection_Binding
Asked: 2012-03-15 08:47:33 +0800
Seen: 923 times
Last updated: Jun 13 '12