html - Angular(keyup)事件仅检测到 # 符号
问题描述
我试图使用角度(keyup)事件来实现搜索栏。我的文件名像
- 根据 @,
- 基础美元,
- 基地1,
- 根据 #,
- 基地2,
当我在搜索栏中搜索 base @ 或 base $ 或 base 1 时,它会很好地过滤。但是当我搜索 base # 它不过滤 base # 它会过滤所有带有 base 的文件名。这是我编写的代码
我的html:
<input type="search" class="form-control" placeholder="Search file" (keyup)="onSearch($event)" [(ngModel)]='searchKeywords'>
我的js代码:
onSearch(event: any) {
const keywords = event.target.value;
if (keywords && keywords.length > 2) {
const apiURL =`abc/thg/hjy?filter[file.name]=${keywords}`;
this.api.get(apiURL).subscribe((data: any) => {
console.log(data);
this.topics = data.list;
if (this.trigger) {
this.trigger.openMenu();
}
});
} else {
this.topics = [];
this.trigger.closeMenu();
}
}
解决方案
现在我可以通过了#
。
onSearch(event: any) {
const keywords = event.target.value;
const params: any = {};
if (keywords && keywords.length > 2) {
params['filter[translations.title]'] = keywords;
const options = {
search: params
};
const apiURL = `abc/thg/hjy`;
this.api.get(apiURL, options).subscribe((data: any) => {
console.log(data);
this.topics = data.list;
if (this.trigger) {
this.trigger.openMenu();
}
});
} else {
this.topics = [];
this.trigger.closeMenu();
}
}
推荐阅读
- email - 电子邮件回复不起作用
- google-tag-manager - 仅当 div-x 存在时才定义槽
- python - 使用 subprocess.run() 和共享输入在 Python 中替换 Bash 进程
- javascript - 数一数注册了多少用户?
- pointers - 尝试读取和写入 proc 时从不兼容的指针类型 [-Werror=incompatible-pointer-types] 初始化错误
- c# - 棱镜事件在发布模式下不起作用
- reactjs - Mobx 状态树嵌套存储注入
- java - 如何在不创建 POJO 的情况下映射标签的值?
- mongoid - 如何将 rails_admin 与 mongoid 一起使用?
- java - 为什么 Apache Velocity 不能处理多个点键