Polymer 1.0上的条件模板

Isk*_*lla 5 polymer polymer-1.0

我认为,我在应用新条件模板时遇到了麻烦,尤其是条件本身.

我有这样的事情:

<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>
Run Code Online (Sandbox Code Playgroud)

现在,如果我评论该<template is="dom-if" if="{{index != 4}}">位它工作正常,索引显示它应该.在第四个阵列上存储了用户选择为不可见的模块,因此它们不应出现在主菜单上.

我想if条件有问题,但我不知道是什么.

谢谢!

vas*_*sek 11

尝试修改您的条件模板,如下所示:

<template is="dom-if" if="{{show(index)}}">
Run Code Online (Sandbox Code Playgroud)

并将此函数添加到Polymer脚本:

show: function (index) {
    return index != 4;
}
Run Code Online (Sandbox Code Playgroud)

  • 您不必创建完整的自定义元素,但如果您想使用_binding syntax_(即`{{}}`),您必须至少使用`dom-bind`模板(https:// www .polymer-project.org/1.0 /文档/ devguide/templates.html#DOM的绑定). (2认同)