Jquery模板插件
嘿,伙计们,我在试这个例子 关于jQuery模板和我做错的事情。 任何帮助都将不胜感激。 这是他的密码: 数据: 客户:Jquery模板插件,jquery,templates,jquery-templates,Jquery,Templates,Jquery Templates,嘿,伙计们,我在试这个例子 关于jQuery模板和我做错的事情。 任何帮助都将不胜感激。 这是他的密码: 数据: 客户: <script id="invoiceTemplate" type="x-jquery-tmpl"> <table class="invoice"> {{each lineItems}} {{tmpl($value) get_invoiceRowTemplateName(type)}} {{/ea
<script id="invoiceTemplate" type="x-jquery-tmpl">
<table class="invoice">
{{each lineItems}}
{{tmpl($value) get_invoiceRowTemplateName(type)}}
{{/each}}
</table>
</script>
{{each lineItems}}
{{tmpl($value)get_invoiceRowTemplateName(type)}
{{/每个}}
Js:
$(函数()
{
$(“#发票模板”).tmpl(发票).appendTo('body');
});
函数get\u invoiceRowTemplateName(类型){
//返回与我们的模板匹配的模板选择器
//行模板的约定。
返回“#”+类型+”行模板“;
}
不要忘记行模板:
<script id="serviceRowTemplate" type="x-jquery-tmpl">
<tr class="service">
<td colspan="2">${service}</td>
<td colspan="2">${price}</td>
</tr>
</script>
<script id="itemRowTemplate" type="x-jquery-tmpl">
<tr class="item">
<td>${item}</td>
<td>${description}</td>
<td>${price}</td>
<td>${qty}</td>
</tr>
</script>
${service}
${price}
${item}
${description}
${price}
${qty}
当get_invoiceRowTemplateName()将每个项目的
类型
解析为相应的*type*RowTemplate时,这些单独的行模板用于呈现每个项目。您可能需要详细说明“错误”的含义。。。你得到输出了吗,输出有问题吗,结果有什么问题,等等etc@Ben它没有做任何事情,但Dave已经回答了我的问题,我缺少“行”模板。
$(function ()
{
$('#invoiceTemplate').tmpl(invoice).appendTo('body');
});
function get_invoiceRowTemplateName(type) {
// Return a template selector that matches our
// convention of <type>RowTemplate.
return '#' + type + 'RowTemplate';
}
<script id="serviceRowTemplate" type="x-jquery-tmpl">
<tr class="service">
<td colspan="2">${service}</td>
<td colspan="2">${price}</td>
</tr>
</script>
<script id="itemRowTemplate" type="x-jquery-tmpl">
<tr class="item">
<td>${item}</td>
<td>${description}</td>
<td>${price}</td>
<td>${qty}</td>
</tr>
</script>