Skip to content

Instantly share code, notes, and snippets.

@gugahoi
Last active December 11, 2015 19:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gugahoi/4647412 to your computer and use it in GitHub Desktop.
Save gugahoi/4647412 to your computer and use it in GitHub Desktop.
keyUp filter function
App.Filter = Ember.TextField.extend({
keyUp: function() {
var array = App.Movies.FIXTURES;
for (var i = array.length - 1; i >= 0; i--) {
var name = array[i].name,
id = array[i].id,
movie = App.Movies.find(id);
if(name.toLowerCase().indexOf(this.get('value')) !== -1){
movie.set('isHidden', false);
} else {
movie.set('isHidden', true);
}
}
}
});
<script type="text/x-handlebars" data-template-name="_movieMenu">
{{view App.Filter class="span12" placeholder="Filter"}}
<ul class="unstyled well">
{{#each movie in controller}}
<li {{bindAttr class="movie.isHidden:hidden:visible"}}>
{{#linkTo "movie" movie}}
{{ movie.name }}
{{/linkTo}}
</li>
{{/each}}
</ul>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment