Revision history [back]

click to hide/show revision 1
initial version

asked 2013-02-22 22:37:06 +0800

Shahbour gravatar image Shahbour

command for a item in list

Hello

i am following MVVM with tabbox children to create different tabs views for different classes, every thing is working perfect except for the command binding from child classes they are always looking at main viewmodel (for label/textbox binding it is working perfect).

Here you can see my main zul page

<tabbox id="maintb" height="100%" apply="org.zkoss.bind.BindComposer" viewModel="@id('vm') @init('xxxxxx.MainViewModel')">
<tabs id="tabs" children="@load(vm.tabList)" 
                onSelect="@command('selecttab',item=each)" onClose="@command('closetab',item=each)">
   <template name="children">
            <tab closable="true" label="@load(each.header)"  />
   </template>
</tabs>
 <tabpanels children="@load(vm.tabList) @template(each.type)">
        <template name="children" var="tab">
            <tabpanel>
                <label value="children" />
            </tabpanel>
        </template>
        <template name="first" var="tab">
            <tabpanel>
                <include src="dashboard.zul"></include>
            </tabpanel>
        </template>
         <template name="CDRServerStatus" var="tab" >
            <tabpanel>
                <include src="cdrserverstatus.zul"></include>
            </tabpanel>
        </template>
    </tabpanels>

</tabbox>

i got differnet templates for different types , now for third template below is the code

<vlayout>
<button label="Get Status" onClick="@command('getstatus')"></button>
<textbox value="@bind(tab.test)"></textbox>
<listbox vflex="true" hflex="1" model="@bind(tab.cDRServerStatusList)">
 <listhead>
       <listheader label="Site" width="80px" align="center" />
       <listheader label="Count" align="center" />
</listhead>
        <template name="model" var="cDRStatusVM">
            <listitem>
                <listcell label="@load(cDRStatusVM.siteName)" />
                <listcell label="@load(cDRStatusVM.CDRsCount)" />
            </listitem>
        </template>

</listbox> </vlayout>

Listbox is showing the items correctly but the button when trying to fire the command it is searching for a command on the mainviewmodel while i want it to search for this tabviewmodel "tab.command" .

I know i can do this using global command but i might want to add multiple tabs of same time so it is not an option.

Is there any way to tell the @command to search in sub context same as i am binding my label and list to tab.property .

Best Regards Shahbour

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