2016-12-15 72 views
11

我正在将1000条记录加载到引导选择下拉列表。 Chrome浏览器大约需要2秒,但在IE 9中需要30秒。另外,取消或x在IE中的引导模式也需要10 + s。 API调用没问题,但渲染速度很慢;有人能给我一些方向吗?引导选择加载在IE中花费太长时间

所以我正在加载一个客户列表并设置所选。这是代码。

var customerPicker = $('#customer-picker'); 
    API.getCustomers().then(function (result) { 
     loadDropdown(customerPicker, result.customers); 

     // set the selected to current customer; it takes 10s in IE 
     customerPicker.val(currentCustomerId).selectpicker('refresh'); 

     // it takes about 10s in IE too. selector is the bs modal div 
     $(selector).css('z-index', '1060').modal('show'); 
    }).catch(function (errorMessage) { 
     ToastManager.showError(errorMessage || 'An error occurred while loading customer list. Please try again.'); 
    }); 

    function loadDropdown($div, arr) { 
     var options = ''; 
     $.each(arr, function (i, item) { 
      options = options + '<option value="' + item.Value + '">' + item.Text + '</option>'; 
     }); 
     $div.html(options); 
    } 

enter image description here

+0

您是否尝试过'$ div.append('

+0

@RobinMackenzie是的,我试过没有运气。 – Quentin

+1

你使用的是什么版本的jQuery?你很可能通过尝试不同的jQuery发布来解决这个问题,因为你提到的两个函数都直接与js打交道。 –

回答

2

您是否尝试过设置循环内的innerHTML;

$div[0].innerHTML += '<option value="' + item.Value + '">' + item.Text + '</option>'; 

而不是在最后。

$div.html(options); 
1

也许你想考虑一个序列化库来处理它一次加载的记录数。 Clusterize.js是一个非常完善的版本,只允许浏览器渲染当前客户端正在查看的内容。它显示任何地方最多可以以这种方式处理100,000个以上的记录。

https://clusterize.js.org/

0

的Jquery可以在旧的浏览器体验的性能损失。 Here's a solution类似于您遇到的情况。与原生JS相比,$.each()已经非常慢了。