How to use if=“some condition” in ZK template tag

南笙酒味 提交于 2020-01-04 04:08:30

问题


I have a <template> tag in my ZUL file, and I want to use this template when some condition accured (for example, when some LABEL's value change to some text).

Please look at below code... As you can see, "templateStatus" is my label's name, but it did not work.

How can I fix this issue?

    <template name="allTaskTemplate" var="allTask" if="templateStatus.value == 'allTask'">
        <row>
            <label value="" />
            <label value="@load(allTask.documentDTO.docTypeDTO.title)"/>
            <label value="@load(allTask.documentDTO.docNumber)"/>
            <label value="@load(allTask.documentDTO.docDateTime)"/>
            <label value="@load(allTask.assignerID)"/>
            <label value="@load(allTask.assigneeID)"/>
            <label value="@load(allTask.assignDateTime)"/>
            <label value="@load(allTask.assignDateTime)"/>
            <label value="@load(allTask.assignDateTime)"/>
            <label value="@load(allTask.assignDateTime)"/>
            <label value="@load(allTask.documentDTO.docTypeStateDTO.stateActionDTO.actionDTO.title)"/>
            <label value="@load(allTask.catalogDTO.catalogTypeDTO.title)"/>
        </row>
    </template>
</grid>

回答1:


Using an if statement:

<zk if="${vm.type=='foo'}">
    <!-- Child components -->
</zk>

<zk if="${vm.type=='check'}">
    <!-- Child components -->
</zk>

<zk if="${vm.type=='something'}">
    <!-- Child components -->
</zk>

<zk if="${vm.type=='value'}">
    <!-- Child components -->
</zk>



回答2:


See the below example of ZK. You can use conditional templates...

<grid model="@bind(vm.itemList) @template(vm.type eq 'foo'?'template1':'template2')">
    <template name="template1">
    <!-- child components -->
    </template>

    <template name="template2">
    <!-- child components -->
    </template>
</grid>

For more information, you can see the official page of ZK, Collection and Selection.

Se the below code for...

   <menubar id="mbar" children="@bind(vm.menuList) @template(empty each.children?'menuitem':'menu')">
    <template name="menu" var="menu">
        <menu label="@bind(menu.name)">
            <menupopup children="@bind(menu.children) @template(empty each.children?'menuitem':'menu')"/>
        </menu>
    </template>
    <template name="menuitem" var="item">
        <menuitem label="@bind(item.name)" onClick="@command('menuClicked',node=item)" />
    </template>
</menubar>

See the above. Using more than two templates you can do something like this. I don't know your requirement, but you can use the above logic and implement it in your code.

Or you can see the ZK Forum for the same, Zk forum.



来源:https://stackoverflow.com/questions/15332500/how-to-use-if-some-condition-in-zk-template-tag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!