Polymer 1.0 dom-repeat不会触发过滤器

时间:2016-09-25 07:46:13

标签: polymer polymer-1.0

有一个简单的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 个答案:

答案 0 :(得分: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. isMondayreturn True中包含拼写错误。在JavaScript中,关键字为小写:true

  4. plunker demo

相关问题