简体   繁体   English

jQuery我应如何在多个html文件中实时搜索结果

[英]jquery how should i search multiple html files for results in realtime

i have this Fiddle Here http://jsfiddle.net/kd6Y4/4/ 我在这里有这个小提琴http://jsfiddle.net/kd6Y4/4/

which is getting div from a different page on same site and display it the problem is its working perfectly online like this direct link http://fiddle.jshell.net/kd6Y4/1/show/ search for hand or and in both 这是从同一网站上的不同页面获取div并显示出来的问题,是它可以像在此直接链接一样完美地在线工作http://fiddle.jshell.net/kd6Y4/1/show/搜索手或两者

but there is a problem if i am searching a html file which is around 7 mb with more than 6000 div its hanging for around 20 seconds before giving results and sometime chrome closes when testing i want to load results from multiple html files at a time and in a way so that results should show instantly and realtime when the searching is being processed and also it should search multiple html files one after other and display results in chronological order please help 但是如果我正在搜索一个HTML文件,它的宽度大约为7 mb,超过6000 div,则存在一个问题,它会在给出结果之前悬挂20秒左右,并且在测试时有时会关闭chrome,我想一次从多个HTML文件中加载结果,以某种方式使结果在处理搜索时应立即显示并实时显示,并且应依次搜索多个html文件并按时间顺序显示结果,请帮助

} http://jsfiddle.net/kd6Y4/4/

Javascript follows a single threading computational model. Javascript遵循单线程计算模型。 Going through that many divs will block the thread. 经过那么多div将阻塞线程。 To avoid this, you can use the parallel computational capabilities of modern processors. 为避免这种情况,您可以使用现代处理器的并行计算功能。

Parallel.js is one such library that exploits this multi core capabilities of modern browsers. Parallel.js是一个利用现代浏览器的多核功能的库。

Say you have 500 divs that needs to be searched. 假设您有500个div需要搜索。

var divs = getDivs();
var worker = new Parallel('search');

worker.spawn(function(divs){
  // do search here
  return result;
}).then(function(result){
  //display the result
});

Here we construct a new parallel worker with name 'search', We then spawn a job, passing in an anonymous function. 在这里,我们构造了一个新的并行工作器,名称为“ search”,然后生成一个工作,并传入一个匿名函数。 This function receives the divs that needs to be searched, and returns the result. 该函数接收需要搜索的div,并返回结果。

Finally, call then to post/show the returned result. 最后,致电, then发布/显示返回的结果。

Parallel depends on the webworker api , which defines an API for spawning background scripts in your web application. 并行依赖于webworker api ,该API定义了用于在Web应用程序中生成后台脚本的API。 This allows you to fire up long-running scripts to handle computationally intensive tasks, but without blocking the UI or other scripts to handle user interactions. 这使您可以启动长时间运行的脚本来处理计算量大的任务,而又不会阻塞UI或其他脚本来处理用户交互。

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

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