将jquery mobile中的页面/加载javascripts与phonegap链接起来的最佳做法是什么?

我的phonegap项目有多个html(超过4个),有一些单页和多页。 当我移动页面时,有时javascript会中断。 也许我错误地链接页面…我一直在谷歌搜索……并得到了很多不同的答案。

  • 有人说包括所有相同的头’因为.js不会被ajax类型的页面加载加载
  • 一些关于app.initialize()的讨论; 一些人谈论’pageinit’。 有人建议使用onload(); 在身体标签。 有人说是pageshow:function(){}。
  • 一些人谈论.Deferred()/ $ .when(deviceReadyDeferred,jqmReadyDeferred).then(doWhenBothFrameworksLoaded); 有这么多方法来初始化!

什么是包含JS文件的最佳实践?

此外,有很多方法可以链接页面。

  • 我想如果一个锚导致多页面的html,使用data-rel =’external’是一种很好的做法。 但有人说data-dom-cache =“true”。 有人说$ .mobile.changePage();

什么是链接页面的最佳实践?

  • 来自单页.html – >多页.html
  • 来自多页.html – >单页.html
  • 来自单页.html – >单页.html
  • 来自多页.html – >多页.html

你能给我一个很好的基础教程吗? 或链接到其中一个? 先感谢您。

你可以尝试我的方法。

的index.html

                    

main.js

 var pagesHistory = []; var currentPage = {}; var path = ""; function init(){ $("body").load(path + "pages/ListPage.html", function(){ $.getScript(path + "js/ListPage.js", function() { if (currentPage.init) { currentPage.init(); } }); }); } 

ListPage.js

 currentPage = {}; currentPage.init = function(){ console.log("ListPage :: init"); }; currentPage.loadPage = function(pageIndex){ console.log("ListPage :: loadPage :: pageIndex: " + pageIndex); $("body").load(path + "pages/" + pageIndex + ".html"); $.getScript(path + "js/" + pageIndex +".js", function() { if (currentPage.init) { currentPage.init(); } }); }; 

ListPage.html

  

ListPage

如果您需要有关此导航的更多说明,请与我们联系。

参考: http : //blog.revivalx.com/2014/07/15/simple-hybrid-mobile-app-using-cordova-and-ratchet-2-complete/

加载页面时不重要。 因为您的所有html文件都包含在您的应用包中。 我已经像以下一样使用了jQuery Mobile;

            
// some header contents
// some contents
. .
// login contents
. .