Polymer 1.0 dom-重复不触发过滤器

Polymer 1.0 dom-repeat does not trigger filter

有一个简单的 paper-card 和一个正在迭代的 iron-ajax,但我制作的过滤器从未触发。通过 iron-ajax 获取的 JSON 具有星期几的整数值,我只想拥有值为 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>
  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. isMondayreturn True 中包含错字。 JavaScript中关键字小写:true.

plunker demo