-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Based on the value we select in the listbox, few textboxes needs to be shown and few textboxes needs to be hidden. How can we handle this using MVVM Approach?
Demonstrate the idea with a simple example:
<div viewModel="@id('vm')@init('org.zkoss.mvvm.viewmodel.HideVM')">
<listbox model="@init(vm.model)" onSelect="@command('update')"/>
<textbox placeholder="group1" visible="@load(vm.group1Visible)"/>
<textbox placeholder="group2" visible="@load(vm.group2Visible)"/>
</div>
public class HideVM {
private ListModelList<String> model = new ListModelList<>();
private boolean group1Visible;
private boolean group2Visible;
public HideVM(){
model.add("group1");
model.add("group2");
}
@Command @NotifyChange({"group1Visible", "group2Visible"})
public void update(){
String selectedItem = model.getSelection().iterator().next();
//determine the rule to update visibility
if (selectedItem.contains("group1")){
group1Visible = true;
group2Visible = false;
}else {
group1Visible = false;
group2Visible = true;
}
}
//omit setter
}
Asked: 2021-04-23 21:25:30 +0800
Seen: 14 times
Last updated: Jul 29 '21