我有这个功能,我将显示数组值,如果输入框中输入的值大于 1,它将比较并显示值。我如何在自定义过滤器中重写它。
users: searchInputModel[] = [
{
name: 'Jack Daniel',
code: 'AD1213'
},
{
name: 'John Doe',
code: 'TFQUN'
}
];
constructor() {
this.userControl.valueChanges.subscribe((user) => {
if (user && user.length > 1) {
this.filteredUsers = user ? this.filterUsers(user) : this.users.slice();
}
});
}
filterUsers(value: string): searchInputModel[] {
const filterValue = value.toLowerCase();
return this.users.filter(user => user.name.toLowerCase().indexOf(filterValue) === 0);
}