简体   繁体   English

如何将 Checkbox 的 onCheck 事件传递给 zk 中的父级?

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

I have a vbox with some checkboxes in it, like so:我有一个带有一些复选框的 vbox,如下所示:

<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?有没有办法让 vbox 对它的任何孩子的 onCheck 事件做出反应?

Edit:编辑:

The vbox is part of a window that has its on viewmodel. vbox 是 window 的一部分,它有它的视图模型。 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.父变量代表 vbox。 The viewmodel of the vbox contains an onSelectionChange method. vbox 的视图模型包含一个 onSelectionChange 方法。 But it seems to never get called.但它似乎永远不会被调用。

You might try this:你可以试试这个:

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

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>

Sometimes it can be so simple....有时它可以如此简单......

I just changed the zul as follows:我只是将zul更改如下:

<vbox onSelectionChange="@command('onChange', component=self)"/>

Now, the event gets propagated correctly.现在,事件得到正确传播。 No need for a viewmodel in this case!在这种情况下不需要视图模型!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM