内存管理在javascript jquery手机与phonegap
Memory management in javascript jquery mobile with phonegap
我正在构建一个jquery手机+ phonegap应用捆绑iOS。JQM站点/应用程序可以在web浏览器上正常工作。然而,当与phonegap捆绑在一起并在手机上测试时,它似乎忘记了javascript函数。例如,我通过滑动打开/关闭面板。在几次滑动之后,~10打开/关闭,它不再响应滑动。我打不开面板。其他按钮仍然可以使用,但我无法进入面板。
在电脑或网络应用程序上,我可以一整天都这样做而不会死机。是否有可能从我的javascript清除函数?或者我应该用另一种方式来定义它们?
$(document).on('pageinit', '#page', function() {
$(document).on("swipeleft swiperight", "#page", function(e) {
console.log('swiped!!')
});
});
任何想法?
更新:显然,只有当我连续来回执行10次时,它才会"忘记"函数。如果我在每次滑动之间留出2-3秒的停顿,它似乎可以运行更长时间。也许新的滑动事件正在发生,而旧的滑动事件仍在完成功能??这就导致它们缠在一起结冰了吗?我一直被这事困住了。任何关于phonegap应用程序的javascript内存管理的帮助/见解将是很好的。
所以,我找到了一个解决方案。
$(document).on('pageinit', '#page', function() {
$(document).on("swipeleft swiperight", "#page", function(e) {
console.log('swiped!!')
});
});
这是我发布的伪代码。结果是,每次滑动时都会调用console.log msg,但是上面代码中省略的面板打开/关闭调用却没有。
完整的旧代码:
$(document).on('pageinit','#page', function(){
$(document).on("swipeleft swiperight", "#page", function(e) {
console.log('swiped!!')
// We check if there is no open panel on the page because otherwise
// a swipe to close the left panel would also open the right panel (and v.v.).
// We do this by checking the data that the framework stores on the page element (panel: open).
if ($.mobile.activePage.jqmData( "panel" ) !== "open") {
if ( e.type === "swipeleft" ) {
$( "#right-panel" ).panel( "open" );
} else if ( e.type === "swiperight" ) {
$( "#left-panel" ).panel( "open" );
}
}
else if ($.mobile.activePage.jqmData( "panel" ) == "open"){
$( "#left-panel" ).panel( "close" );
$( "#right-panel" ).panel( "close" );
}
});
}
这些修改修复了以下代码:将选择器从swipelleft swiperight功能中移除$(document).on("swipeleft swiperight", "#page", function(e) {}
变成了$(document).on("swipeleft swiperight", function(e) {}
我在事件中添加了e.stopPropagation()
。我认为这一定是JQM事件传播冒泡DOM和破坏一切。
$(document).on('pageinit', '#page', function() {
$(document).on("swipeleft swiperight", function(e) {
e.stopPropagation();
console.log('swiped!!')
// We check if there is no open panel on the page because otherwise
// a swipe to close the left panel would also open the right panel (and v.v.).
// We do this by checking the data that the framework stores on the page element (panel: open).
if ($.mobile.activePage.jqmData( "panel" ) !== "open") {
if ( e.type === "swipeleft" ) {
$( "#right-panel" ).panel( "open" );
} else if ( e.type === "swiperight" ) {
$( "#left-panel" ).panel( "open" );
}
}
else if ($.mobile.activePage.jqmData( "panel" ) == "open"){
$( "#left-panel" ).panel( "close" );
$( "#right-panel" ).panel( "close" );
}
});
}
- 从手机中选择多个图像'使用phonegap的多媒体资料
- GCM推送通知,如果应用程序在手机中关闭(Phonegap Android)
- Phonegap:如何控制手机的字体大小
- 具有PhoneGap的手机上的网络应用程序
- Phonegap Android项目适用于模拟器,而不是实际的手机
- 返回到索引.html从图像.html通过使用PhoneGap Android中的“手机后退”按钮
- Phonegap不会在手机中显示谷歌地图
- 本地存储在Windows手机PhoneGap应用程序中不起作用
- 为什么在Win8手机应用程序上使用PhoneGap
- 使用phonegap和Sencha Touch访问Android手机联系人
- 内存管理在javascript jquery手机与phonegap
- Phonegap检测手机是否处于活动状态
- 如何在javascript中检测平板电脑和智能手机[Phonegap App]
- 使用javascript使用phonegap调用手机短信api
- 带有phonegap的后退按钮(并查询手机?)
- jquerymobile -如果javascript在手机设置中被禁用,将phonegap + jquerymobile
- 如何在Phonegap Android中查找用户手机号码
- 如何保护HTML5+PhoneGap手机应用中的数据
- Jquery手机用phonegap回页错误
- 我需要做些什么来设置手机应用程序编程在android的phonegap