Reputation:
I'm trying to debounce my search function but I get an error. I have an ember search input and this in my array controller:
App.PostsController = Ember.ArrayController.extend({
watchSearch: function() {
Em.run.debounce(this, this.itemsa, 400);
}.observes("search"),
itemsa: function() {
var searched = this.get("search") ? this.get("searchedItems") : this;
return searched;
}.property("searchedItems"),
searchedItems: function() {
var search = this.get('search').toLowerCase();
return this.filter(function(item) {
return item.get('title').toLowerCase().indexOf(search) != -1;
})
}.property('search', 'title')
});
And in my template I have:
<script type="text/x-handlebars" id="posts">
{{#each itemsa}}
{{title}}
{{/each}}
</script>
Upvotes: 1
Views: 1655
Reputation: 47367
debounce should call a function, not a computed property.
App.PostsController = Ember.ArrayController.extend({
watchSearch: function() {
Em.run.debounce(this, this.runSearch, 400);
}.observes("search"),
runSearch: function(){
this.set('nextSearch', this.get('search'));
},
itemsa: function() {
var searched = this.get("search") ? this.get("searchedItems") : this;
return searched;
}.property("searchedItems"),
searchedItems: function() {
var search = this.get('search').toLowerCase();
return this.filter(function(item) {
return item.get('title').toLowerCase().indexOf(search) != -1;
})
}.property('nextSearch', 'title')
});
Upvotes: 2