如何过滤聚合物1.0中的铁清单? [英] How to filter an iron-list in polymer 1.0?

查看:80
本文介绍了如何过滤聚合物1.0中的铁清单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

dom-repeat元素提供一个filter属性.

是否有使用iron-list进行过滤的类似方法?

Is there a similar way to filter with iron-list?

例如:给定一个人的名单,我想过滤一个特定城市中出生的人.

For example: Given a list of people, I want to filter the ones born in a specific city.

推荐答案

不幸的是,由于iron-list没有提供filter属性,因此没有声明式模式可以实现这一目的.

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

您可以使用dom-repeat的filter属性来实现自己的简单列表元素. (随着元素继承在将来的版本中重新出现,您可以扩展iron-list.)

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>

这篇关于如何过滤聚合物1.0中的铁清单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆