Conditional Template for Polymer 1.0

I am having problems using the new conditional template, in particular with the condition itself.

I have 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 on the <template is="dom-if" if="{{index != 4}}"> bit, it works fine, the index shows how it should be. The fourth array contains modules that the user selected as invisible, so they should not be displayed in the main menu.

I assume that something is wrong with the if condition, but I can’t guess what.

Thanks!

+5
source share
1 answer

Try changing your conditional pattern as follows:

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

And add this function to the Polymer script:

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

All Articles