English 中文(简体)
取消退学选择
原标题:Remove dropdown options performance issue

我需要了解最快的方法,从减少名单中删除数百个选择。

Right now, Firefox is really slow at updating my 2nd drop down dynamic list. Chrome is doing OK with the script but I need to speed up my removal of:

<select id="myDropDown" name="myDropDown">
<option value=1>1</option>
<option value=2>2</option>
<option value=3>3</option>
<option value=4>4</option>
<option value=5>5</option>
... all the way to let s say 500
</select>

Repopulating it is a breeze. I have a json parser that creates the <option></option> fields.

我尝试:

.remove()
.children().remove()   
.empty()

他们在排除数百种选择方面表现得同样缓慢。 是否有人失踪?

问题回答

你们是否试图通过他们进行 lo?

$( #myDropDown option ).each(function(i, option){ $(option).remove(); });

You can specify which ones by keeping track of the value of i.

问题。 我认为,如果你希望它真正迅速,你就只能展示/宣布选择。

$("#someOption").hide();

EDIT: I think you may have an array of values that have to populate, let s say values. It d be fast if you traverse your options first and check for each one if it s in the values array (not vice versa, would be slow). So having:

var values = [...]; //Array with values that must  exist  in the dropdown
$("#select1 option").each(function(i, option){
   option.style.display = ($.inArray(option.value, values) >= 0 ?  block  :  none );
});

值得注意的是,我们重新避免圈子内的支部选择,以提高业绩。 我们没有穿过第一组阵列(和内部的选择),因为搜索阵列的速度要快得多(在这种情况下是选择),而独有的属性(在本案中是价值)在占支配地位。

希望这一帮助。 卡车

问题可能是,j Query在去除物品时试图进行清理,读到,()详细内容(从“以避免记忆泄露......>开始)。

如果你认为这在你的处境中是一个问题,那么,你就认为,这确实是一个问题。

$("#someOption").text("");

或许是你所需要的轮.。

$("#myDropDown").find("option").remove();




相关问题
What to look for in performance analyzer in VS 2008

What to look for in performance analyzer in VS 2008 I am using VS Team system and got the performance wizard and reports going. What benchmarks/process do I use? There is a lot of stuff in the ...

SQL Table Size And Query Performance

We have a number of items coming in from a web service; each item containing an unknown number of properties. We are storing them in a database with the following Schema. Items - ItemID - ...

How to speed up Visual Studio 2008? Add more resources?

I m using Visual Studio 2008 (with the latest service pack) I also have ReSharper 4.5 installed. ReSharper Code analysis/ scan is turned off. OS: Windows 7 Enterprise Edition It takes me a long time ...

Manually implementing high performance algorithms in .NET

As a learning experience I recently tried implementing Quicksort with 3 way partitioning in C#. Apart from needing to add an extra range check on the left/right variables before the recursive call, ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

热门标签