javascript - lodash debounce 忽略空格键
问题描述
嗨,我正在与 lodash 合作 .. 一切都很好 .. 但我有一个问题,那就是当按下 enter 键时我希望 debouce 不工作 .. 这是我的 lodash 键 ..
search_products:_.debounce(function(event)
{
// my code here
// how can i let debounce work with all keys but not with enter key
},5),
如果有任何其他方法,如 debouce 或任何花药库,我也希望延迟 5ml 不能与 enter 一起使用,任何人都可以在这里帮助我,谢谢
解决方案
您可以提取 debounced 函数,并且仅在按下回车键以外的其他内容时调用它。
{
search_products: function (event) {
if (event.code !== 'Enter') {
debounced(event);
}
}
}
const debounced = _.debounce(function(event) {
// ...
}, 5);
推荐阅读
- android - OAuth2 Google Fit 同意屏幕无限加载
- c# - 如何从 C# 中的类响应中填充数据表变量值
- python - 删除开始和结束符号之间的文本
- assembly - 了解aarch64汇编函数调用,栈是如何操作的
- ios - 快速调用函数内部的函数
- javascript - 使用 firestore 获取更新的值
- flutter - dart Grpc 的拦截器
- google-cloud-platform - 由于 VPC 连接器注释,部署 Cloud Run 服务失败
- php - Symfony 5 缓存组件 AWS elasticache 无效 DSN
- php - Yii2 - 下载损坏的文件