[英]How to filter an iron-list in polymer 1.0?
The dom-repeat
element offers a filter
attribute. dom-repeat
元素提供了filter
属性。
Is there a similar way to filter with iron-list
? 是否有类似的方法来过滤
iron-list
?
For example: Given a list of people, I want to filter the ones born in a specific city. 例如:给定一个人列表,我想过滤掉在特定城市出生的人。
As iron-list
unfortunately doesn't offer a filter
attribute, there is no declarative pattern making this possible. 不幸的是,
iron-list
没有提供filter
属性,因此没有声明模式使这成为可能。
You can either implement your own simple list element making use of dom-repeat
's filter property. 您可以使用
dom-repeat
的filter属性实现自己的简单列表元素。 (With element inheritance coming back in future releases, you might extend iron-list
). (在将来的版本中会返回元素继承,你可以扩展
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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.