问题
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