我正在尝试在每次用户在自动完成框中键入内容时调用的 API 函数中实现去抖动。但不知何故,当我输入一些东西时,它会调用主 API 函数而不是去抖函数。下面是代码:
$scope.searchTextChange = function(searchText){
debounceSearch(getAllIds(searchText),1000); //getAllIds get called everytime upon keyboard input
}
const debounceSearch= (callback, delay) => {
let timeout = null;
return (...args) => {
const next = () =>
callback(...args);
clearTimeout(timeout);
timeout = setTimeout(next, delay);
}
}
牧羊人nacy
相关分类