How can I pass on the onCheck event of a Checkbox to its parent in zk?

余生颓废 提交于 2019-12-24 03:52:50

问题


I have a vbox with some checkboxes in it, like so:

<vbox id="myVbox" apply="org.zkoss.bind.BindComposer"
   viewModel="@id('vm') @init('my.checkbox.group.CheckboxGroupViewModel', outerVM=wvm, component=self)">
   <checkbox id="1"/>
   <checkbox id="2"/>
   <checkbox id="3"/>
</vbox>

Is there a way to make the vbox react to any of its children's onCheck event?

Edit:

The vbox is part of a window that has its on viewmodel. In it, there is the following code to add the radios dynamically:

if (childName.equals("org.zkoss.zul.Checkbox")) {
                    child.addEventListener("onClick", new EventListener<Event>() {
                        @Override
                        public void onEvent(Event event) throws Exception {
                            Events.sendEvent(new Event("onSelectionChange",parent));                        
                        }                       
                    });
                }

The parent variable represents the vbox. The viewmodel of the vbox contains an onSelectionChange method. But it seems to never get called.


回答1:


You might try this:

<vbox onSelectionChange="@command('METHODNAME_TO_IMPLEMENT_EVENT')"/>



回答2:


How do you want it to react? You could do something like:

<vbox id="myVbox">
    <checkbox id="1" onCheck="myVbox.visible=false"/>
    <checkbox id="2"/>
    <checkbox id="3"/>
</vbox>


来源:https://stackoverflow.com/questions/58537258/how-can-i-pass-on-the-oncheck-event-of-a-checkbox-to-its-parent-in-zk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!