【发布时间】:2017-12-20 06:03:57
【问题描述】:
我正在我的网站上构建一个表单,允许用户从数据库中搜索客户,为此我预加载了客户,然后设置了一个 Angular 4 自动完成组件以使用客户列表,但是渲染下拉菜单时它运行得非常慢。我确定这是因为要显示的结果太多了,通常超过 6000 个。
有没有办法让自动完成功能使用我构建的自定义函数,该函数等到它确定用户在返回结果之前完成输入,现在我正在使用与角度示例中显示的完全相同的代码。
这是组件背后的TS代码:
this.filteredCustomers = this.customerControl.valueChanges
.startWith(null)
.map(val => val ? this.filterCustomers(val) : null);
filterCustomers(val: string): any {
return this.agencyCustomers.filter(function (item: any) {
var n = item.Name.trim().toLowerCase();
return (n.search(val) >= 0);
});
}
这里是html:
<md-autocomplete #customers="mdAutocomplete">
<md-option *ngFor="let customer of filteredCustomers | async" [value]="customer.Name" [innerText]="customer.Name" (onSelectionChange)="customerChanged(customer, transaction)">
</md-option>
</md-autocomplete>
非常感谢任何帮助。
【问题讨论】:
-
你能提供一个plnkr吗?
-
尝试使用primeng组件primefaces.org/primeng/#/autocomplete
-
PrimeNG 效果很好,正是我想要的,谢谢!
标签: angular autocomplete observable