Javascript Backbonejs下划线限制的函数未启动
我想筛选一个主干集合。因此,我想限制keyup事件,并在用户完成键入或暂停时触发 我的油门前功能正在启动,我正在获取日志(“油门前”)。但是,实际的筛选器Bytle未启动。有什么建议吗Javascript Backbonejs下划线限制的函数未启动,javascript,backbone.js,underscore.js,backbone-events,Javascript,Backbone.js,Underscore.js,Backbone Events,我想筛选一个主干集合。因此,我想限制keyup事件,并在用户完成键入或暂停时触发 我的油门前功能正在启动,我正在获取日志(“油门前”)。但是,实际的筛选器Bytle未启动。有什么建议吗 linkApp.Views.FilteredLinks = Backbone.View.extend({ el:'#divFilter', events:{ 'keyup #filterTitle': "filterByTitleThrottled" }, i
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');
}
});
当您调用-时,它将创建并返回传递函数的新版本。
在此之后,你可以使用她:
filterByTitleThrottled:function(){
console.log('before throttle');
var trottle = _.throttle(this.filterByTitle, 100);
trottle();
}
我认为最好在初始化时对这个.filterBytle进行节流,使其正常工作
initialize:function(){
this.filterByTitle = _.throttle(this.filterByTitle, 100);
},
你将节流一次,你会得到你期望的结果