我有关于使用ZK6的新树绑定机制进行模型绑定的问题。 首先,这是我的代码:
祖尔:
<div id="win" apply="org.zkoss.bind.BindComposer"
viewModel="@id('vm') @init('mira.web.composer.PermissionDesignerModel')"
style="width:98%; text-align:center;" vflex="1">
<tree id="permissionTree" width="100%" model="@bind(vm.treeModel)"
style="text-align:left;" vflex="2">
<treecols>
<treecol label="Item" width="400px" />
<treecol label="Typ" />
<treecol label="Ausgabe" />
<treecol label="Einfügen" width="100px" />
</treecols>
<template name="model" var="node">
<treeitem open="@bind(node.open)">
<treerow>
<treecell>
<textbox value="@bind(node.data.name)" />
</treecell>
<treecell>
<combobox mold="rounded" readonly="true"
model="@load(vm.allAttributeTypes)"
selectedIndex="@bind(node.data.attType)">
<template name="model">
<comboitem label="@load(each.name)"
value="@load(each.id)" />
</template>
</combobox>
</treecell>
<treecell>
<checkbox label="Ausgabe"
checked="@bind(node.data.isOutput)" />
</treecell>
<treecell>
<button label="Einfügen"
onClick="@command('insertNode', node=node)" />
</treecell>
</treerow>
</treeitem>
</template>
</tree>
模特:
public class PermissionDesignerModel {
ClassPathResource res = new ClassPathResource("/beans.xml");
BeanFactory beanFactory = new XmlBeanFactory(res);
private PermissionTreeModel treeModel;
@Command
public void insertNode(@BindingParam("node") PermissionTreeNode node) {
node.setOpen(false);
}
public PermissionTreeModel getTreeModel() throws ParseException {
if (treeModel == null) {
PermissiontreeBuilder builder = new PermissiontreeBuilder(Container
.getCurrentProduct().getProductId());
PermissionTreeNode root = builder.getRoot();
setTreeModel(new PermissionTreeModel(root));
}
return treeModel;
}
public void setTreeModel(PermissionTreeModel treeModel) {
this.treeModel = treeModel;
}
}
正确调用了insertNode()方法,并且我获得了包含内容的相应节点,但是当我更改节点(或open-attribute)的数据时,UI中没有任何内容。我是否必须调用一些特殊的bind()方法或类似的东西让模型更改在树中生效?
答案 0 :(得分:2)
好吧,我找到了答案:你必须手动通知UI(每个变量)。
@NotifyChange({ "treeModel" })
@Command
public void insertNode(@BindingParam("node") PermissionTreeNode node) {
PermissionTreeNode addNode = node;
if(node.getChildren() == null) {
PermissionItem item = node.getData();
PermissionTreeNode parent = (PermissionTreeNode) node.getParent();
int index = parent.getIndex(node);
parent.remove(node);
addNode = new PermissionTreeNode(item, new ArrayList<PermissionTreeNode>());
parent.insert(addNode, index);
}
addNode.add(new PermissionTreeNode(new PermissionItem()));
}
在NotifyChange中,您可以在方法中添加要更改的变量。