使用jTemplates,可以像这样合成模板...
<textarea id="templateList" class="template"><!--
{#template RESULTS}
This a template for generating a list of results
{#include PAGINATION root=$T}
{#/template RESULTS}
{#template PAGINATION}
This is a template for generating pagination through the results
{#/template PAGINATION}
--></textarea>然而,有时候能够组合完全不同的模板会很方便。例如,我有许多不同类型的列表,每个列表都有一个不同的模板。使用上面的方法,我不得不在不同列表的每个模板中一遍又一遍地重复相同的代码块进行分页。
我更愿意做下面这样的事情……
<textarea id="templateList" class="template"><!--
This is a template listing results
{#some kind of call to templatePagination}
--></textarea>
<textarea id="templatePagination" class="template"><!--
This is a template for generating pagination
--></textarea>有没有人知道这样的事情是否可能,如果是的话,该如何去做呢?
谢谢!
发布于 2010-09-15 22:59:16
如果没有模板引用,您可以在setTemplate时将所有需要的模板附加在一起。
$(container)
.setTemplate($('templateList').html() + $('templatePagination').html())或者,您可以createTemplate并将引用作为include传递
var t = $.createTemplate($('templatePagination').html());
$(container).setTemplate($('templateList').html(), t._templates)发布于 2010-12-23 05:34:37
您应该能够执行以下操作:
var templates = $.createTemplate($('templateList').html())._templates;然后,您可以使用模板并执行以下操作:
$('#SOMEDIV').setTemplate(templates['PAGINATION'],templates);
&('#SOMEDIV').processTemplate(data);我是一个js/jquery新手,如果它不完美,我很抱歉。我使用$.createTemplateURL而不是我们的文本区域从url加载它
https://stackoverflow.com/questions/3696821
复制相似问题