大数组迭代(200000) - 任何优化机会? [英] Large Array Iteration (200000) - any chance for optimization?

查看:99
本文介绍了大数组迭代(200000) - 任何优化机会?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!


我的项目有以下界面:(截图效果最好)
http://www.screencast.com/users/asch...9-4a7af883e3c9


设备组可以有1台设备或100,000台设备。


当您选择其他设备组时,我有异步操作

- 它将转到服务器,获取适用的设备 - 从列表中删除

当前设备,然后重新添加它拥有的所有设备

检索。


这需要很长时间,大约20,000个设备(20-30秒)。

这是我的代码:


//结果是一个字符串数组

函数populateDeviceList(结果){

var listBox = $(''。DeviceList '')[0];


//清除列表

for(var i = listBox.options.length - 1; i > = 0; i--){

listBox.options [i] = null;

}


//重新填充结果

var deviceListFilterBox = $(''。DeviceListFilterBox'')[0] .value;

var len = result.length;

for(var i = 0; i< len; i ++){

var thisOne = result [i];

if(thisOne.startsWith(deviceListFilterBox)){

AddItem(listBox ,thisOne,thisOne);

}

}

disableSelectedItems($(''body''));

}


函数AddItem(objListBox,strText,strId,added)

{

var newOption = new Option(strText) ,strId)

objListBox.options.add(newOption);

}


有什么建议吗?


提前致谢!

Hello!

My project has the following interface: (screenshot works the best)
http://www.screencast.com/users/asch...9-4a7af883e3c9

Device groups could have 1 device, or 100,000 devices.

I have an asynchronous action when you select a different device group
- it will go to the server, get the applicable devices - remove the
current devices from the list, then re-add all the devices it has
retrieved.

This takes a long time with around 20,000 devices (20-30 seconds).
Here''s my code:

//result is an array of strings
function populateDeviceList(result){
var listBox = $(''.DeviceList'')[0];

//Clear the list
for (var i = listBox.options.length - 1 ; i >= 0 ; i--) {
listBox.options[i] = null;
}

//Repopulate with results
var deviceListFilterBox = $(''.DeviceListFilterBox'')[0].value;
var len = result.length;
for (var i = 0;i < len;i++){
var thisOne = result[i];
if (thisOne.startsWith(deviceListFilterBox)){
AddItem(listBox, thisOne, thisOne);
}
}
disableSelectedItems($(''body''));
}

function AddItem(objListBox, strText, strId, added)
{
var newOption = new Option(strText, strId)
objListBox.options.add(newOption);
}

Any suggestions?

Thanks in advance!

推荐答案

(''。DeviceList'')[0];

//清除清单

for(var i = listBox.options.length - 1; i> = 0; i--){

listBox.options [i] = null;

}


//重新填充结果

var deviceListFilterBox =
(''.DeviceList'')[0];

//Clear the list
for (var i = listBox.options.length - 1 ; i >= 0 ; i--) {
listBox.options[i] = null;
}

//Repopulate with results
var deviceListFilterBox =


(''。DeviceListFilterBox'')[0] .value;

var len = result.length;

for(var i = 0 ;我< len; i ++){

var thisOne = result [i];

if(thisOne.startsWith(deviceListFilterBox)){

AddItem(listBox,thisOne,thisOne);

}

}

disableSelectedItems(
(''.DeviceListFilterBox'')[0].value;
var len = result.length;
for (var i = 0;i < len;i++){
var thisOne = result[i];
if (thisOne.startsWith(deviceListFilterBox)){
AddItem(listBox, thisOne, thisOne);
}
}
disableSelectedItems(


(''body''));

}


函数AddItem(objListBox,strText,strId,added)

{

var newOption = new Option(strText,strId)

objListBox.options.add(newOption);

}


有什么建议吗?


提前致谢!
(''body''));
}

function AddItem(objListBox, strText, strId, added)
{
var newOption = new Option(strText, strId)
objListBox.options.add(newOption);
}

Any suggestions?

Thanks in advance!


这篇关于大数组迭代(200000) - 任何优化机会?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆