代码之家  ›  专栏  ›  技术社区  ›  Let Me Tink About It

聚合物1.0:帮助使用dom,如果

  •  12
  • Let Me Tink About It  · 技术社区  · 9 年前

    请有人提供一个正确实施 dom-if ?

    official documentation . (抱歉,没有直接链接。必须使用左上角的菜单,然后选择 dom如果 ).

    这是我到目前为止的情况。很明显,它不起作用。

    <template>
      ...
      <template is="dom-if" if="{{action}}=='Login'">
           <!-- Also tried: if="{{action=='Login'}}" -->
        <a href="#">Forgot password?</a>
      </template>
      ...
    </template>
    
    3 回复  |  直到 8 年前
        1
  •  30
  •   Iain J. Reid agektmr    7 年前

    这很麻烦,但你必须这样做:

    <template is="dom-if" if="[[_actionIsLogin(action)]]">
      <a href="#">Forgot password?</a>
    </template>
    
    <script>
      Polymer({
        ...
        _actionIsLogin: function(action) {
          return action === 'Login';
        }
        ...
      });
    </script>
    

    显式创建一个函数,该函数返回 true false .

        2
  •  4
  •   Zohar81    9 年前

    我认为以下示例非常简单,易于理解/实现(不在您提供的链接中):

    https://www.polymer-project.org/1.0/docs/devguide/templates.html

    从页面。。。

    <div>{{user.name}}</div>
    
    <template is="dom-if" if="{{user.isAdmin}}">
      Only admins will see this.
      <div>{{user.secretAdminStuff}}</div>
    </template>
    ...
    

    希望它有帮助。

        3
  •  1
  •   Cesar SC    8 年前
    <template>
        <iron-ajax           
                auto
                url="https://jsonplaceholder.typicode.com/todos"
                handle-as="json"
                last-response="{{baul}}">
        </iron-ajax>
    
        <template is="dom-repeat" items="{{baul}}" >
            <template is="dom-if" if="{{item.completed}}">{{item.title}} is completed<br></template>
        </template>
    
    
    </template>