How to filter an iron-list in polymer 1.0?

北城以北 提交于 2019-12-03 13:33:28
daluege

As iron-list unfortunately doesn't offer a filter attribute, there is no declarative pattern making this possible.

You can either implement your own simple list element making use of dom-repeat's filter property. (With element inheritance coming back in future releases, you might extend iron-list).

However, the best practice I currently see is the use of a computed property:

<template>
  <iron-list items="[[filterItems(items)]]" as="item">
    ...
  </iron-list>
</template>

<script>
Polymer({
  ...
  filterItems: function (items) {
    return items.filter(function (item) { // Array.prototype.filter
      return item.priority > 8; // Filter condition
    });
  }
});
</script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!