Skip to content

Instantly share code, notes, and snippets.

@juanhuttemann
Last active October 31, 2017 22:23
Show Gist options
  • Select an option

  • Save juanhuttemann/7460c5b4a23c75e4602f9a6b952ace01 to your computer and use it in GitHub Desktop.

Select an option

Save juanhuttemann/7460c5b4a23c75e4602f9a6b952ace01 to your computer and use it in GitHub Desktop.
Filterby + Input + RegEx Emberjs
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