如何过滤聚合物1.0中的铁清单? [英] How to filter an iron-list in polymer 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屋!