0
我已經添加了一個選擇全部/取消選擇所有包裝選項的Select2多選控件。在IE8中處理Select2中多個選項的選擇 - 性能問題
它的工作原理是通過選項循環,推值到一個數組,然後將數組傳遞給selct2 VAL如下:
mySelect2.select2("val", mySelectedValuesArray);
這工作正常,在Chrome和在情況下,有沒有這麼多要選擇的選項。但在IE8中,它們可能有100多個選項,瀏覽器會凍結,因爲它試圖呈現選定的值,並且我得到多個停止運行此腳本?警報。在使用可擴展文本框時,IE8遇到了類似的問題,瀏覽器在必須增加文本框高度並凍結IE瀏覽器渲染引擎時凍結。無論如何,在這種情況下,只要您選擇超過30或40個選項的所有選項,就會使頁面無法使用。
我已經嘗試手動創建所選選項容器的標記,以便一次添加它,但是,除了表單然後必須手動連接每個單擊事件以便能夠頂部刪除它們,Im找到選擇更改事件觸發它時,select2結束刪除選項無論如何,我無法找到一個方法。
任何想法?
爲更新這裏是我的代碼
$(".filterIconContainer .filtericon").on("click",function() {
var $this = $(this);
var $associatedSelect = $("#" + $this.attr("data-associated-select"));
if ($associatedSelect.length == 0) {
$associatedSelect = $("#filterContainer div[data-tabid='" + $("#filterTabs li.active").attr("id") + "'] select");
}
if ($this.attr("data-action") == "select") {
var selected = [];
$associatedSelect.find("option").each(function (i, e) {
selected.push($(e).attr("value"));
});
setTimeout(function() {
$associatedSelect.select2("val", selected); // Browser throws stop running this script alert during select2 processing this line
$associatedSelect.change(); // call the change event to force any post change action
},5);
}
else {
$associatedSelect.select2('val', '');
$associatedSelect.change(); // call the change event to force any post change action
}
});