Conditional template on Polymer 1.0

7.9k Views Asked by At

I'm having trouble applying the new conditional template, in particular with the condition itself, I think.

I've got something like this:

<template is="dom-repeat" items="{{menuitems}}" as="poscol">
    <template is="dom-if" if="{{index != 4}}">
        <div class="positioncolum horizontal layout center wrap flex">
            <span>{{index}}</span>
            <template is="dom-repeat" items="{{poscol}}" as="mitem" >
               <main-menu-item mitem="{{mitem}}"
                   order="{{mitem.TotalOrder}}"
                   onclick="clickMainMenuMod(index)">
               </main-menu-item>
            </template>
       </div>
   </template>
</template>

Now, if I comment the <template is="dom-if" if="{{index != 4}}"> bit it works fine, the index shows as it should. On the fourth array are stored modules that the user has selected as non-visible, so they shouldn't appear on the main menu.

I guess there's something wrong with the if condition, but I can't guess what.

Thanks!

1

There are 1 best solutions below

6
On BEST ANSWER

Try to modify your conditional template like this:

<template is="dom-if" if="{{show(index)}}">

And add this function to Polymer script:

show: function (index) {
    return index != 4;
}