0

forEach as a inner loop in outer template/model loop

asked 2012-05-23 13:17:35 +0800

khcyt gravatar image khcyt
216 1 1

Hello, I want to combine template/model in conjunction with new ZK6 bind mechanism (for handle dynamic data) and the legacy forEach (see first window below).
Unfortunately I can not access to "each" in the inner loop. "each" still refers to the outer "each".

If I use forEach in both loops (see second window), everything works as expected. Nested template/model loop works too, but I would not nested listboxes.
Is there a way to correct access to "each"?

Kai

<?xml version="1.0" encoding="UTF-8"?>


<zk>
    <zscript><![CDATA[
        ListModel lm= new ListModelList();
        
        Object[] data= new Object[2];
        data[0]= "Today"; 
        data[1]= new String[] { "RE: Bandbox Autocomplete Problem",
				"RE: It's not possible to navigate a listbox' ite",
				"RE: FileUpload" };
        lm.add(data);
        
        data= new Object[2];
        data[0]= "Yesterday"; 
        data[1]= new String[] { "RE: Opening more than one new browser window",
				"RE: SelectedItemConverter Question" };
        lm.add(data);

        data= new Object[2];
        data[0]= "Last Week"; 
        data[1]= new String[] { "RE: Times_Series Chart help",
				"RE: SelectedItemConverter Question" };
        lm.add(data);

        class VM
        {
            public ListModel getListModel()		{ return lm; } 
        }
	]]></zscript>

	<window id="win" title="Window ZK6 bind and inner forEach" border="normal" width="600px" 
    		apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('VM')" >    		    	
		<listbox model="@bind(vm.listModel)">
		   <template name="model">
		      <listitem>
		      	<listcell label="@load(each[0])"/>
		      	<listcell>
                    <vlayout>
                    <zk forEach="${each[1]}">
                        <label value="${each}"/>
                    </zk>
                    </vlayout>
		      	</listcell>
		      </listitem>
		   </template>
		</listbox>
    </window>

    <window id="win_2" title="old Style forEach" border="normal" width="600px">    		    	
		<listbox forEach="${lm}">
		      <listitem>
		      	<listcell label="${each[0]}"/>
		      	<listcell>
                    <vlayout>
                    <zk forEach="${each[1]}">
                        <label value="${each}"/>
                    </zk>
                    </vlayout>
		      	</listcell>
		      </listitem>
		</listbox>
    </window>

</zk>

delete flag offensive retag edit

2 Replies

Sort by ยป oldest newest

answered 2012-05-30 03:28:43 +0800

benbai gravatar image benbai
2228 6
http://www.zkoss.org

Hi,

It does not work in 6.0.0 but works fine with latest freshly, not sure how about with ZK 6.0.1.

Regards,
Ben

link publish delete flag offensive edit

answered 2012-05-30 06:36:27 +0800

khcyt gravatar image khcyt
216 1 1

Thanks for that answer Ben. I'll test it when a new version (6.0.2 or so) available.

Kai

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2012-05-23 13:17:35 +0800

Seen: 266 times

Last updated: May 30 '12

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More