Android 上的 JQuery.Hive(工作线程)
我目前正在编写一个应用程序,显示我们大学食堂的菜单计划。 为了使其独立于平台,我使用 Phonegap; XML 解析是在 JQuery 的帮助下完成的,布局是用 JQuery Mobile 生成的。
在我的 motorola defy 上解析菜单的 XML 文件大约需要 1-2 秒。例如,如果您通过单击单选按钮将位置更改为另一个自助餐厅,则 GUI 会在这一秒冻结。我在 JavaScript 中发现了工作线程的概念,并决定将 XML 数据的解析委托给工作线程。不幸的是,我不得不发现 JQuery 无法在工作线程中工作:-( 然后我找到了插件 JQuery.hive,它似乎解决了我的问题。我现在在 hive 环境中创建线程,发送消息,在内部处理它工作线程并收到答案。 不幸的是,这仅适用于 Firefox,不适用于我的 Android/Phonegap 应用程序。
这是我生成工作线程的地方:
$(function() {
$("#mydiv").append("Start |");
$.Hive.create({
worker : 'Worker_Parser.js',
receive : function(data) {
$("#mydiv").append('RECEIVED MESSAGE: ' + data.message + ' | ');
}
});
$("#mydiv").append("Worker generated | ");
});
$.Hive.get(0).send("test");
$("#mydiv").append("End ");
这是工作线程:
importScripts('jquery.hive.pollen.js');
$(function (data) {
$.send("test");
});
Firefox 显示
Start | Worker generated | End | RECEIVED MESSAGE: test |
Android Broswer 在尝试启动线程时取消脚本并仅显示:
Start |
JQuery.hive 是否应该在 Android 下运行? 有没有更好的方法来解决我在不冻结 GUI 的情况下解析 XML 的问题?
预先感谢,
汤姆
i am currently writing an app that shows the menu plan of the cafeteria at our university.
To make it platform-independent i use Phonegap; The XML-Parsing ist done with the help of JQuery, the layout is generated with JQuery Mobile.
Parsing the XML-File for the menus takes around 1-2 seconds on my motorola defy. If you for example change the location to another cafeteria by clicking the radio button the GUI freezes for this second. I found the concept of Worker Threads in JavaScript and decided to delegate the parsing of the XML-data to a Worker Thread. Unfortunately i had to find out that JQuery does not work within Worker Threads :-( Then i found the Plugin JQuery.hive which seemed to solve my problems. I now create the Thread within the hive-environment, send a message, process it inside the Worker Thread and receive an answer.
Unfortunately this works only in Firefox and not in my Android/Phonegap-Application.
This is where i generate the Worker:
$(function() {
$("#mydiv").append("Start |");
$.Hive.create({
worker : 'Worker_Parser.js',
receive : function(data) {
$("#mydiv").append('RECEIVED MESSAGE: ' + data.message + ' | ');
}
});
$("#mydiv").append("Worker generated | ");
});
$.Hive.get(0).send("test");
$("#mydiv").append("End ");
This is the worker thread:
importScripts('jquery.hive.pollen.js');
$(function (data) {
$.send("test");
});
Firefox shows
Start | Worker generated | End | RECEIVED MESSAGE: test |
The Android Broswer cancels the script when attemping to start a Thread and shows only:
Start |
Is JQuery.hive supposed to run under Android at all?
Is there a better way to solve my problem of parsing XML without freezing the GUI?
Thanks in advance,
Tom
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看这里,您会发现当前的 Android 浏览器不支持 Web Workers,iOS 也不支持。
您能否在 XML 文件中进一步分解数据,并根据用户交互将其分成更小的块发送,而不是立即发送整个菜单?也许只将菜单请求缩小到当天并触发其他日期的 AJAX 请求?
Looking here, you'll see that Web Workers are not supported by the current Android browser, nor by iOS.
Could you break the data down further in the XML file, and send it in smaller chunks based on user interaction, instead of sending the whole menu at once? Perhaps shrink the menu request only to the current day and fire off AJAX requests for other days?