admin管理员组文章数量:1332339
I want to filter a backbone collection. Hence, i want to throttle the keyup event and fire when user is done typing or take a pause.
My before throttle function is firing and i am getting the log('before throttle'). However, actual filter filterByTitle is not firing. Any suggestion?
linkApp.Views.FilteredLinks = Backbone.View.extend({
el:'#divFilter',
events:{
'keyup #filterTitle': "filterByTitleThrottled"
},
initialize:function(){
},
render:function(){
},
filterByTitleThrottled:function(){
console.log('before throttle');
_.throttle(this.filterByTitle, 100);
},
filterByTitle:function(){
console.log('actual filter by title');
}
});
I want to filter a backbone collection. Hence, i want to throttle the keyup event and fire when user is done typing or take a pause.
My before throttle function is firing and i am getting the log('before throttle'). However, actual filter filterByTitle is not firing. Any suggestion?
linkApp.Views.FilteredLinks = Backbone.View.extend({
el:'#divFilter',
events:{
'keyup #filterTitle': "filterByTitleThrottled"
},
initialize:function(){
},
render:function(){
},
filterByTitleThrottled:function(){
console.log('before throttle');
_.throttle(this.filterByTitle, 100);
},
filterByTitle:function(){
console.log('actual filter by title');
}
});
Share
Improve this question
asked Nov 10, 2013 at 21:35
Jhankar MahbubJhankar Mahbub
9,84810 gold badges50 silver badges52 bronze badges
2 Answers
Reset to default 11I think it would be better to _.throttle this.filterByTitle on initialize to make it works properly.
initialize:function(){
this.filterByTitle = _.throttle(this.filterByTitle, 100);
},
You'll throttle it once and you'll get result that you're expecting.
When you call to _.throttle
- it's creates and returns a new version of the passed function.
And after this you can use her:
filterByTitleThrottled:function(){
console.log('before throttle');
var trottle = _.throttle(this.filterByTitle, 100);
trottle();
}
本文标签: javascriptBackbonejs underscore throttled function is not firingStack Overflow
版权声明:本文标题:javascript - Backbonejs underscore throttled function is not firing - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742330426a2454582.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论