angularjs - dataSource.filter 过滤在前端不可见的 ID
问题描述
基本上,这是我的代码
applySearchFilter(filterValue: string) {
this.values = filterValue.toString().toLowerCase();
this.dataSource.filter = this.values;
} 使用“this.dataSource.filter”我可以从中过滤掉任何数据,但我想为 keyId 添加一个例外......请参见下面的对象。
我的对象看起来像这样。
{
keyId: "00000000-0000-0000-0000-000000010001",
name: "Test 10",
location: "New York"
}
当我输入“10”时,它会过滤数据源中包含 10 的所有内容。因此,不仅名称中包含“10”,而且 keyId 中也包含。我花了一个小时才意识到这一直在发生……这是因为 keyId xD
尽管我得到了包含 keyId 的整个对象,但 keyId 没有显示在前端,并且不应该是搜索/过滤的。即使它没有在前端显示 keyId,他也会搜索具有该 keyid 的对象
我现在不知道如何修复它,因为像this.dataSource.data.name这样的东西不起作用......
如果你们女孩和女孩能给我一些建议,我将不胜感激。
哦,这是我将数据过滤到的地方。
public getObject(): void {
this.service.getObjectMethod().then(data=> {
this.dataSource.data = data;
}, (err: Error) => { console.log(err.message); });
}
解决方案
我解决了这个问题。
public filterData(): void {
if (this.inputValues.trim().length !== 0) {
this.filteredValues = [];
this.dataSource.data.filter(data => {
if (data.name.toLowerCase().includes((this.inputValues).toLowerCase()) ||
data.opensCategory.toLowerCase().includes((this.inputValues).toLowerCase())) {
return true && this.filteredValues.push(data);
}
});
this.dataSource.data = this.filteredValues;
}
}
推荐阅读
- mysql - 是否有可能在 Mysql 中触发 sql 以增加学习年列
- android - BaseFragment 与 android 中的视图绑定
- python - Ec2 未正确反映 github 更改
- mysql - Docker Compose - 无法访问数据库
- html - 网格项目中的文本对齐问题
- python - MongoDB 连接问题;蟒蛇 3.8.7
- macos - macOS 请求网络读写权限
- css - 调整 n 张图片的大小以适应特定的高度和宽度 - 正确的位置/类来定义属性?
- python - SyntaxError:无效语法“如果堆栈[-1].pop()!=括号[堆栈[-2].pop()]:”
- python - 递归的 try 和 except 块的问题