简体   繁体   English

页面挂断,搜索太多

[英]Page hangs up, too much to search

I used PHP to create an HTML page, which compiles a list of data points and pushes them into an array, declares the array in the header, and also echo's a huge list of form input objects into the body. 我使用PHP创建了一个HTML页面,该页面编译数据点列表并将其推入数组中,在标题中声明该数组,并将大量的表单输入对象回显到主体中。 The list I'm working with is just under 15,000 lines which are put into 1 array. 我正在使用的列表不到15,000行,它们被放入1个数组中。

I more or less created a search box that when I blur() an action is supposed to occur, Javascript function is supposed to search through the array and hide unmatched form options and display matches. 我或多或少创建了一个搜索框,当我执行blur()时,应该执行一个动作,Javascript函数应该在数组中搜索并隐藏不匹配的表单选项并显示匹配项。 This seems to work fine up to 5000 but if I have it run through all 15000 array items it hangs up and freezes. 这似乎可以正常工作到5000,但是如果我在所有15000数组项目中运行它,它就会挂起并冻结。

I'm currently hosting it on a free site while I test... here is the link to the actual page TEST PAGE that hangs up 我目前正在测试时将其托管在一个免费网站上...这是到挂起的实际页面“ 测试页面”的链接

I'm including a snippet of the JS code with a truncated array so you don't have to scroll for thousands of lines. 我包括了一个带有截断数组的JS代码片段,因此您不必滚动数千行。

  <script type="text/javascript" > var array_ICDDx = new Array('[ICD Code] Diagnosis','[001.0] Cholera due to vibrio cholerae','[001.1] Cholera due to vibrio cholerae el tor','[001.9] Cholera, unspecified','[002.0] Typhoid fever','[002.1] Paratyphoid fever A','[002.2] Paratyphoid fever B','[002.3] Paratyphoid fever C','[002.9] Paratyphoid fever, unspecified','[003.0] Salmonella gastroenteritis','[003.1] Salmonella septicemia','[003.20] Localized salmonella infection, unspecified','[003.21] Salmonella meningitis','[003.22] Salmonella pneumonia','[003.23] Salmonella arthritis','[003.24] Salmonella osteomyelitis',[...GOES ON FOREVER ~15000 ARRAY VALUES...]); function searchICDDx(ICDDx,line_start,line_end) { for (var a = line_start; a < line_end; a++) { var ICDDx_check = array_ICDDx[a].toLowerCase(); var Row = "R" + a; if (ICDDx_check.search(ICDDx) >= 0) { document.getElementById(Row).style.display = "block"; } else { document.getElementById(Row).style.display = "none"; } } if (line_end < array_ICDDx.length) { line_end += 1000; if (line_end > array_ICDDx.length) { line_end = array_ICDDx.length; } var timer = setTimeout(searchICDDx(ICDDx,a,line_end),100); // searchICDDx(ICDDx,a,line_end); } // else if (line_end >= array_ICDDx.length) { // clearTimeout(timer); return; // } } function searchICD() { var find_ICD = Coder.elements['ICD'].value; if (find_ICD != "") { document.Coder.Dx.value = ""; find_ICD = find_ICD.toLowerCase(); searchICDDx(find_ICD,1,1000); } } function searchDx() { var find_Dx = Coder.elements['Dx'].value; if (find_Dx != "") { document.Coder.ICD.value = ""; find_Dx = find_Dx.toLowerCase(); searchICDDx(find_Dx,1,1000); } } </script> 

It doesn't appear to be an issue with the code not functioning. 代码不起作用似乎不是问题。 As I mentioned, if I limit the search to just 1000 array values it seems to work, its the massive amount of array values that is killing the page. 正如我提到的,如果将搜索限制为仅1000个数组值,那么它似乎可以工作,大量的数组值正在杀死该页面。

Any suggestions? 有什么建议么? Thank you in advance! 先感谢您!

With this many data points, you should probably do this on the server. 有这么多数据点,您可能应该在服务器上执行此操作。 However, you can try the following: 但是,您可以尝试以下操作:

  • instead of using a for loop (which completely freezes the browser until it is done), use a setInterval that checks a new result every 5 ms or so. 而不是使用for循环(它会完全冻结浏览器直到完成),而应使用setInterval每隔5毫秒左右检查一次新结果。 Periodically, check if all the results have been searched, and clear the interval if so. 定期检查是否已搜索所有结果,如果有,请清除间隔。 It will still take a bit to search, but won't freeze the browser. 搜索仍然需要一些时间,但不会冻结浏览器。

  • search only until you have a set number of results (40 or so), and store the last index of the array that was searched. 仅搜索,直到获得一定数量的结果(大约40个),然后存储所搜索数组的最后一个索引。 Wait to load more searches until the user scrolls down the page. 等待加载更多搜索,直到用户向下滚动页面。

Also, you should probably implement an infinite scroll for displaying results. 另外,您可能应该实现无限滚动以显示结果。 My browser froze and had to be restarted just opening the link you attached. 我的浏览器死机了,只需要打开您附加的链接就必须重新启动。

Update: if you don't want the items displayed until after you search, you should have no items on the page initially and add them when they match the search. 更新:如果您不希望在搜索后显示任何项目,则最初页面上应该没有任何项目,并在与搜索匹配时添加它们。 This prevents the initial lag, prevents you from having to change the visibility of every element, and reduces the number of elements on the page (which causes issues). 这样可以防止初始滞后,避免您必须更改每个元素的可见性,并减少页面上元素的数量(这会引起问题)。

Thank you for all your input and suggestions. 感谢您的所有意见和建议。

I went back and took out all of entries when listed in the form. 我回去并取出了表格中列出的所有条目。 Then I had JS create a list of checkbox inputs based on all the positive results and element.innerHTML the results. 然后,我让JS根据所有肯定的结果和element.innerHTML结果创建一个复选框输入列表。 The array is still a huge list on client side through which the JS searches for matches. 该数组在客户端仍然是一个庞大的列表,JS可以通过该列表搜索匹配项。 I updated the code in the link from my original post to show the faster and working result. 我更新了原始文章链接中的代码,以显示更快且更有效的结果。

  <script type="text/javascript" > var array_ICDDx = new Array('[icd code] diagnosis','[001.0] cholera due to vibrio cholerae','[001.1] cholera due to vibrio cholerae el tor','[001.9] cholera, unspecified','[002.0] typhoid fever','[002.1] paratyphoid fever a',[...etc...]); function searchICDDx(array_Results,ICDDx,line_start,line_end) { for (var a = line_start; a < line_end; a++) { if (array_ICDDx[a].indexOf(ICDDx) >= 0) { array_Results.push("<span style='display:block' ><input type='checkbox' value='"+array_ICDDx[a]+"' >"+array_ICDDx[a]+"</span>"); } } if (line_end < array_ICDDx.length) { line_end += 1000; if (line_end > array_ICDDx.length) { line_end = array_ICDDx.length; } searchICDDx(array_Results,ICDDx,a,line_end); } else if (line_end >= array_ICDDx.length) { var string_Results = array_Results.join("\\n"); document.getElementById("Results_here").innerHTML = string_Results; return; } } function searchICD() { var array_Results = new Array(); var find_ICD = Coder.elements['ICD'].value; if (find_ICD != "") { document.Coder.Dx.value = ""; find_ICD = find_ICD.toLowerCase(); searchICDDx(array_Results,find_ICD,1,1000); } } function searchDx() { var array_Results = new Array(); var find_Dx = Coder.elements['Dx'].value; if (find_Dx != "") { document.Coder.ICD.value = ""; find_Dx = find_Dx.toLowerCase(); searchICDDx(array_Results,find_Dx,1,1000); } } </script> 

In the past I've had poor results with forms and innerHTML added options, which I'll tackle another time when I try to move this code into the larger project. 过去,使用表单和innerHTML添加选项的效果不佳,当我尝试将这段代码移入更大的项目时,我将解决另一个问题。

Thank you again 再次感谢你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM