2

我在使用 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() 方法,并且我得到了包含内容的适当节点,但是当我更改节点的数据(或打开属性)时,UI 中没有任何反应。我是否必须调用一些特殊的 bind() 方法或其他东西才能使模型更改在树中生效?

4

1 回答 1

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 中,您可以在方法中添加正在更改的变量。

于 2012-07-17T19:58:27.840 回答