简体   繁体   中英

Conditional template on Polymer 1.0

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!

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;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM