组织 jQuery Mobile 应用程序的最佳实践是什么?

编程入门 行业动态 更新时间:2024-10-28 00:19:31
本文介绍了组织 jQuery Mobile 应用程序的最佳实践是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我发现 文章 略过了这一点.但我的主要问题是每个屏幕都需要一个单独的 .html 文件吗?我想是的,但我想要一致投票.另外,这也适用于单独的 JS 文件吗?

I have found article that skims over this. But my main question is do I need a separate .html file for each screen? I am thinking yes but I would like an unanimous vote. Also, does that go for separate JS files too?

JQM 应用基本上是针对管理员用户和角色的.

JQM app is basically to admin users and roles.

推荐答案

我们有一个生产 jQM 站点,这里是我们做事的方式 - 是的,其他人可能不同意,但我们发现这适用于一个非常大的站点.

We have a production jQM site here's how we do things - and yes others may disagree but we found this works for a very large site.

  • 使用多个单个 HTML 页面,大型多页面模板会抵消 jQM ajax 加载的好处,因为您在开始时加载所有 HTML(除非您的网站很小)

  • Use multiple single HTML pages, a large multi-page template defeats the benefits of jQM's ajax loading since you're loading all your HTML at the start (unless your site is small)

    你肯定想使用ajax加载,jQM只在你的<div data-role="page">中拉入代码但这会使你的JS复杂化,见下文

    You definitely want to use ajax loading, jQM only pulls in the code in your <div data-role="page"> BUT this complicates your JS see below

    你不需要多个 JS 文件,但你需要在开始时加载所有的 JS,我们通过做两件事来完成这个:1.我们把一个 on 侦听器在文档根目录,并侦听 pageinit/pageshow 事件.每次加载页面时,这些都会被触发,您还可以方便地引用当前页面,并且您可以使用页面上的 attr 来确定它是哪个页面.2. 将所有 JS 包含在某种类型的包含中(希望您使用的是 PHP、CF 或其他东西)并将其放在每个页面上,无论用户浏览您的移动设备的哪个入口点网站,他们会加载所有代码

    You don't need multiple JS files, BUT you do need to load all your JS at the start, we accomplish this by doing two things: 1. we put an on listener at the document root, and listen for pageinit/pageshow events. Everytime a page is loaded these are triggered, you also have a handy reference to the current page, and you can use an attr on the page to determine what page it was. 2. Have all the JS in an include of some sort (hopefully you are using PHP, CF or something) and put this on every page, that way no matter which entry point a user browses to your mobile site with, they get all the code loaded

    缺点是最初加载了所有 JS,但缩小后我们发现这没什么大不了的,如果真的很担心,请查看 RequireJS - 而且它使调试变得轻而易举,因为 JS 就在那里,我们可以轻松地使用调试器并放置断点.如果你在每个页面上动态加载 JS,你会增加你需要在每个页面转换上返回的数据,你会变得丑陋,因为你重新加载了多余的 JS,并且很难调试动态 JS.

    The downside is that all the JS is loaded initially, but minified we find it's no big deal, and if it's really a concern look into RequireJS - plus it makes debugging a breeze since the JS is all there we can easily use the debugger and place breakpoints. If you load JS dynamically on each page you increase the data you need to return on each page transistion and you have ugliness because you reload redundant JS and it's hard to debug dynamic JS.

    $(document).on('pageinit pageshow', 'div:jqmData(role="page"), div:jqmData(role="dialog")', function(oEvent){ var pageType = $(this).data('pagetype'); //handle pageinit/pageshow (oEvent.type) for each pageType
  • 更多推荐

    组织 jQuery Mobile 应用程序的最佳实践是什么?

    本文发布于:2023-11-08 11:50:24,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1569292.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:应用程序   组织   jQuery   Mobile

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!