I'm using the repeat template of Dart Polymer to show the items of list. Now, I would like to implement a search filter, where only the items are displayed, which relates to the typed search term. Consider the following code:
my-element.html
<polymer-element name="my-element">
<script type="application/dart" src="my-element.dart"></script>
<template>
<input type="text" value="{{ searchTerm }}">
<ul>
<template repeat="{{ item in items }}">
<template if="{{ matchesSearchFilter(item) }}">
<li>{{ item }}</li>
</template>
</template>
</ul>
</template>
</polymer-element>
my-element.dart
@CustomTag('my-element')
class MyElement extends PolymerElement {
@observable List<String> items = toObservable(["Monday", "Tuesday", "Wednesday"]);
@observable String searchTerm = '';
MyElement.created() : super.created();
matchesSearchFilter(String item) {
if (searchTerm.isEmpty) return true;
return item.toLowerCase().contains(searchTerm.toLowerCase());
}
}
For example, when I type "Mo" in the textbox, I would expect that the list of items updates automatically, such that only "Monday" is shown. However on typing any search term, the list remains the same and the search term is ignored.
So, how to implement such a feature correctly?
searchTermgets set and ifmatchesSearchFiltergets called? - Günter ZöchbauersearchTermis set correctly.matchesSearchFiltersgets called when the list is rendered for the first time (but not whensearchTermhas changed). - melmac