我正在尝试使用es6中的jquery做一个过滤器库项目,而我
出现此错误:未捕获的TypeError:this.filterProjects不是
功能。我想这个错误与该关键字有关,但我不确定
要修复
import $ from 'jquery';
class ProjectsModal{
constructor(){
this.btnCategories=$(".our-works__btn-categories h3");
this.projects=$(".our-works__images li");
this.events();
}
events(){
this.btnCategories.click(this.filterByCategory);
}
filterByCategory(){
var category=$(this).text().toLowerCase();
this.filterProjects(category);
}
filterProjects(category){
if (category=='all') {
this.projects.fadeIn('slow');
} else {
this.projects.each(function(){
if (!$(this).hasClass(category)) {
$(this).hide();
} else {
$(this).fadeIn('slow');
}
});
}
}
}
export default ProjectsModal;