[英]How to reuse html code for multiple pages in jquery mobile.?
we are developing mobile app using jquery mobile & phonegap for various customers. 我们正在使用jquery mobile和phonegap为各种客户开发移动应用程序。 Almost all the requirement completed but current requirement is each customer expecting different structure of html.
几乎所有已完成的要求,但当前的要求是每个客户都期望html的结构不同。 how to make this possible satisfy the requirement?
如何做到这一点满足要求?
i can duplicate of all pages and change the structure of html based on customers. 我可以复制所有页面,并根据客户更改html的结构。 But it difficult to maintain all these files i think so
但是我很难维护所有这些文件
in mvc we having partial view to achieve this, we expecting something same like partial view in html. 在mvc中,我们有部分视图来实现这一点,我们期望类似html中的部分视图。
Thanks in Advance 提前致谢
Here are couple of approaches I have used in the past in different situations, in decreasing order of my personal preference: 以下是我过去在不同情况下使用的几种方法,按照我个人喜好的降序排列:
1) Use JSP
if your pages are going to live on the server and employ @include
s to incorporate fragments of reusable JSP in a master page. 1)使用
JSP
,如果你的页面是要住在服务器上,并采用@include
s到纳入可重复使用的JSP的片段在母版页。
2) Use a template engine to place client-specific HTML fragments. 2)使用模板引擎放置客户端特定的HTML片段。 You will be interleaving your business rules in the template's query language.
您将使用模板的查询语言来交错业务规则。
3) Use Jquery
if your pages are packaged in a client app and use $.load()
to load fragments of HTML. 3)如果您的页面打包在客户端应用程序中,请使用
Jquery
并使用$.load()
加载HTML片段。 You will have to ensure that you do this before JQM
begins its own life-cycle and fires its init
events. 您将必须确保在
JQM
开始其自己的生命周期并触发其init
事件之前执行此操作。
4) Use a Ant
build script to do a client specific build using Ant's replace
and token
match tasks. 4)使用
Ant
构建脚本使用Ant的replace
和token
匹配任务来进行特定于客户端的构建。 YMMV with this approach based on the complexity of rules you need to check to create a page. 使用这种方法的YMMV根据您需要检查以创建页面的规则的复杂性。 Ant is just one option;
蚂蚁只是一种选择。 any other build tool will provide similar function.
任何其他构建工具都将提供类似的功能。
You will probably end up using multiple techniques from above for a complete solution. 您可能最终将从上面使用多种技术来获得完整的解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.