Last active
October 31, 2017 22:23
-
-
Save juanhuttemann/7460c5b4a23c75e4602f9a6b952ace01 to your computer and use it in GitHub Desktop.
Filterby + Input + RegEx Emberjs
This file contains hidden or 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 Controller from '@ember/controller'; | |
| import { isBlank } from "@ember/utils"; | |
| export default Controller.extend({ | |
| searchKeyword: "", | |
| updateList: Ember.computed('searchKeyword', function(){ | |
| var keyword = this.get('searchKeyword') | |
| var regex = new RegExp(keyword, "gi"); | |
| if (isBlank(keyword) || (keyword.length < 2)) { | |
| return this.get('model') | |
| } else { | |
| // return this.get('model').filterBy('name', keyword) | |
| return this.get('model').filter(function (item) { | |
| return item.name.match(regex); | |
| }) | |
| } | |
| }) | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment