【问题标题】:Slow behaviour of angular-ui-select's drop down list when big list of items in Modal当 Modal 中的项目列表很大时,angular-ui-select 下拉列表的缓慢行为
【发布时间】:2016-10-30 20:35:39
【问题描述】:

我在引导模式窗口中使用 angular-ui-select 和大约 1500 个项目的列表。

用户执行的每个操作都有 2 秒的延迟。 我试图通过使用“最小输入长度”来提高性能,但过滤器不起作用。

Plunkr 示例: https://plnkr.co/edit/H0kbeR4kHfZFjsBnpjBC?p=preview

我的 HTML:

<ui-select multiple sortable="true" ng-model="vm.selected" theme="select2" style="width: 100%;">
              <ui-select-match placeholder="Select...">{{ $item.name }}</ui-select-match>
              <ui-select-choices repeat="item in vm.items | filter: $select.search" minimum-input-length="2">
                <div ng-bind-html="item.name | highlight: $select.search"></div>
              </ui-select-choices>
            </ui-select>
  1. 有人知道如何提高性能吗?
  2. 如何应用最小字符过滤器?

    谢谢。

【问题讨论】:

    标签: angularjs ui-select angular-ui-select


    【解决方案1】:

    如果您还使用orderBy 对列表进行排序(这会进一步减慢速度),请确保它位于过滤器链的最后:

    repeat="item in list | propsFilter: {name:$select.search} | limitTo:100 | orderBy:'name'">
    

    现在它将仅对过滤后的值进行排序,而不是对整个列表进行排序。这在一定程度上提高了性能,但并不能解决根本问题。

    【讨论】:

      【解决方案2】:

      我使用 LimitTo 解决了这个问题,检查了搜索长度:

      limitTo: ($select.search.length <= 2) ? 0 : undefined"
      

      完整代码:

      <ui-select-choices 
        repeat="item in ctrl.items | filter: $select.search | limitTo: ($select.search.length <= 2) ? 0 : undefined">
      

      【讨论】:

      【解决方案3】:

      我相信最小长度仅适用于使用刷新功能。 性能仍然是一个问题,因为有很多问题。

      Documentation of uiselect

      触发刷新功能前所需的最少字符数

      【讨论】:

      • 据我了解,“刷新”功能仅用于将数据源定义为 $http 请求。在我的示例中,我已经将所有数据存储在局部变量中。
      • 这是正确的,但“最小输入长度”仅适用于刷新功能。 (据我所知)。下面的一些 ui-select 代码,您可以在其中看到最小输入长度将触发刷新功能。 if (!attrs.minimumInputLength || $select.search.length >= attrs.minimumInputLength) { $select.refresh(attrs.refresh); }
      • 所以我最好尝试找到不同的库来从列表中选择项目?
      • 视情况而定,您可以在Limit link 列表中添加限制。假设您最初加载 10/20 个项目。如果用户随后搜索特定值,您可以使用 wiki 上描述的刷新功能。其次,您可以加载列表并仅附加用户正在搜索的值。
      • 我会尝试在列表上实现延迟加载。性能问题是否与 ng-repeat 创建太多观察者有关?
      猜你喜欢
      • 2016-01-02
      • 2014-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多