2016-09-25 68 views
1

有一個簡單的paper-cardiron-ajax這是迭代好,但我從來沒有觸發過濾器。該JSON是通過獲取鐵阿賈克斯的整數值一週的一天,我只是想和0聚合物1.0多米諾重複不會觸發過濾器

值試過過濾器領域與下列值的:

filter="{{isMonday}}" 
filter="{{isMonday(item)}}" 
filter="isMonday" 
filter="isMonday(item)" 

所有這些與不observe

組件代碼:

<dom-module id="se-ligor"> 
    <template> 
     <template is="dom-bind"> 
      <iron-ajax auto 
         url="http://localhost:5000/leagues/1" 
         handle-as="json" 
         last-response="{{ajaxResponse}}"> 
      </iron-ajax> 
      <template name="my-paper" is="dom-repeat" items="[[ajaxResponse]]" filter="{{isMonday}}" observe="dayofweek"> 
       <paper-card heading="[[item.name]]"> 
        <div class="card-content"> 
         [[item.description]] 
         [[item.dayofweek]] 
        </div> 
        <div class="card-actions"> 
         <paper-button>Some action</paper-button> 
        </div> 
       </paper-card> 

      </template> 


     </template> 

    </template> 
    <script> 
    Polymer({ 
     is: "se-ligor", 
     isMonday: function (item) { 
      console.log(item.dayofweek); 
      if (item.dayofweek == 0) 
       return True; 
     } 
    }); 
    </script> 
</dom-module> 

回答

4
  1. dom-bind模板僅用於綁定index.html,而不是dom-module,因此應刪除模板。

  2. filter屬性採用您的Polymer構造函數對象上沒有分隔符(即,無括號)的方法的名稱。

    <!-- in <dom-module> --> 
    <template is="dom-repeat" items="[[x]]" filter="isMonday" observe="dayofweek">...</template> 
    
    <script> 
        Polymer({ 
        isMonday: function(item) {...} 
        }); 
    </script> 
    
  3. isMonday包含return True一個錯字。在JavaScript中,關鍵字是小寫字母:true

plunker demo