The dom-repeat
element offers a filter
attribute.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With