zkzul

zk element if @load equals condition


I have a list which I build in zul file.

<listbox id="someId" model="@load(vm.searchResults)" selectedItem="@bind(vm.selectedItem)" vflex="1" multiple="true">
    <listhead>
        <listheader label="${labels.l1}" width="150px" align="center"/>
        <listheader label="${labels.l2}" width="150px" align="center"/>
        <listheader label="${labels.l3}" width="100px" align="center"/>
    <listheader label="${labels.l4}" width="400px" align="center"/>
    </listhead>
    <template name="model">
        <listitem style="text-align: left;">
            <listcell style="word-wrap: break-word; text-align: left;">
                <label value="@load(each.l1)"/>
            </listcell>
            <listcell style="word-wrap: break-word; text-align: left;">
                <label value="@load(each.l2)"/>
            </listcell>
            <listcell style="word-wrap: break-word; text-align: left;">
                <label value="@load(each.l3)"/>
                <a action="" label="should be displayed when some param is equals to 3 " if="{each.someParam=='3'}"/>
            </listcell>
            <listcell style="text-align: left;">
                <label value="@load(each.l4)"/>
            </listcell>
        </listitem>
    </template>
</listbox>

I need to display a element when each some param is 3. How do I get it?

<a action="" label="should be displayed when some param is equals to 3 " if="{each.someParam=='3'}"/>

I checked this How to use if="some condition" in ZK template tag

But it did not help me.

I also tried

<a action="" label="should be displayed when some param is equals to 3 " if="{@(each.someParam)=='3'}"/>

Did not work either. '3' or 3 does not change anything. If I remove if condition a element is displayed. But I want to display it only when it meets if condition.

Please help me


Solution

  • Nice that you solved your problem.
    I'll make this answer so you can have more understanding why it didn't work.

    First of all, the if attribute can't handle dynamic data.
    So only decleration with ${...} (static) can work.
    With ZK 8, there is a new tag, <if test="">, and this can handle dynamic data.

    It's not the problem that you need to set the if in a <zk> tag but the problem in your example is the @ or the missing $.
    This may be said, the @{...} is deprecated databinding.
    It's the evolution to MVVM pattern but it was so crapy that they deprecated it and also removed most of the documentation about this, witch is a good case so nobody new can learn to use this.

    Maybe a suggestion of what could help you :

    <style>
        .makeYourName {
            word-wrap: break-word; 
            text-align: left;
         }
    </style>
    

    and then create your listcell like :

    <listcell sclass="makeYourName">
    

    could save you time when you need to refactor your styling.