【发布时间】:2019-08-21 00:22:00
【问题描述】:
我已将 lodash debounce 连接到一个运行良好的输入,但我似乎无法调用其他方法。我尝试在构造函数中绑定搜索。这是我的代码:
class SearchBar {
constructor() {
this.searchState = {
term: '',
loading: false,
};
this.$searchBar = $('.ngaire-search-form > input');
this.onLoad();
this.onSearch = _.debounce(this.onSearch.bind(this), 400);
}
onLoad() {
this.$searchBar.on('keyup change', this.onSearch);
}
onSearch(e) {
const searchTerm = e.currentTarget.value;
if (searchTerm.length > 0) {
console.log(searchTerm); // this works
this.verifySearchTerm(searchTerm); // i get this is not a function
}
}
【问题讨论】:
标签: javascript ecmascript-6 lodash