Created
May 28, 2016 00:17
-
-
Save httpJunkie/1a8dc8993b1377b4aad8a1079adaa653 to your computer and use it in GitHub Desktop.
Aurelia ValueConverter - Array Filter by Text Input
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class ArrayFilterValueConverter { | |
toView(array, value) { | |
var regex = new RegExp(value, 'gi'); | |
var matcher = (item) => | |
item.utilityName.match(regex); | |
return array.filter( | |
matcher | |
); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<require from="./arrayFilter"></require> | |
<input type="text" placeholder="search somelist name" name="somelist" value.bind="searchValue"/> | |
<p>Results</p> | |
<div repeat.for="item of somelist | arrayFilter:searchValue"> | |
<div> | |
<a href="#">${item.name}</a> | |
</div> | |
</div> | |
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {inject} from 'aurelia-framework'; | |
import {SomelistData} from './somelistData'; | |
@inject(UtilityNameData) | |
export class Search { | |
constructor(somelistData) { | |
this.data = somelistData; | |
this.somelist = []; | |
this.searchValue = ""; | |
} | |
activate() { | |
return this.data.getAll() | |
.then(somelist => { | |
this.somelist = somelist; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment