Angular4 AutoComplete 运行速度非常慢,如何加快速度

标签 angular autocomplete observable

我正在我的网站上构建一个表单,允许用户从数据库中搜索客户,为此,我预加载客户,然后设置 Angular 4 自动完成组件以使用客户列表,但是渲染下拉菜单时运行速度非常慢。我确定这是因为要显示的结果太多,通常超过 6000 个。

有没有办法让自动完成功能使用我构建的自定义函数,该函数会等到确定用户完成输入后再返回结果,现在我正在使用与 Angular 示例中显示的完全相同的代码。

这是组件背后的 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>

非常感谢任何帮助。

最佳答案

在下拉列表中使用虚拟列表,仅渲染小块。

例如 - http://rintoj.github.io/angular2-virtual-scroll/

关于Angular4 AutoComplete 运行速度非常慢,如何加快速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45114790/

相关文章:

php - 我如何配置 Vim 以对 D 注释也使用 PHP 样式自动完成?

javascript - 可观察或观察者中的错误处理?

javascript - Openlayers 5 如何观察 view.center 的变化

c# - Angular + ASP.NET Core Web API : 404 on new controller endpoints

用于指令更改检测的 Angular2 事件

jquery - 如何使用 jQuery 自动完成功能限制用户只能选择 4 个值

arrays - 大型数组的自动完成

Angular RouteReuseStrategy 后退按钮/交叉模块

css - 文本区域的模板驱动表单验证

wpf - 在 F# 中访问 XAML (WPF) 元素