【发布时间】:2013-08-02 13:14:36
【问题描述】:
我正在开发一个大型混合移动应用程序 (PhoneGap/HTML5),它必须包含大量视图和服务器调用。在网上搜索了一番后,我发现我可以用 RequireJS、Backbone 和 jQuery Mobile 来组织我的代码。我关注了this tutorial,很有帮助,但我不是很满意……
问题是,当我按下链接或按钮时,RequireJS 会加载每个视图,它会替换上一个视图的内容...我的意思是,<body></body> 之间的整个 HTML 代码都被替换为内容的新观点。如果我决定不替换以前的代码并附加新代码,那么应用程序可能不是非常用户友好。
我曾想过将所有视图分开并将它们放在多个 HTML 文件中,并编写一个 Javascript 来加载所有 HTML 文件并将它们附加到主体,但我不知道这是否是一个好习惯和如果我的应用程序将非常用户友好。这是我如何组织代码的示例:
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<!-- ... -->
</head>
<body>
<!-- Here will be added the content of all the other HTML files -->
</body>
</html>
<!-- homeView.html -->
<div data-role="header" data-theme="f">
<h1 data-i18n="sections.home.title"></h1>
</div>
<div data-role="content">
<h1 data-i18n="sections.home.welcome"></h1>
</div>
<!-- otherView.html -->
<div data-role="header" data-theme="f">
<h1 data-i18n="sections.otherView.title"></h1>
</div>
<div data-role="content">
<p data-i18n="sections.otherView.content"></p>
</div>
你们怎么看?有没有人有更好的解决方案?我的目标是构建一个强大、流畅且可维护的应用程序。
感谢您的帮助。
【问题讨论】:
标签: mobile backbone.js cordova requirejs hybrid-mobile-app