嘿,伙计们,我正在尝试来自Dave Ward blog的这个例子
关于jQuery模板和一些我做错了的事情。任何帮助都将不胜感激。下面是他的代码: Data:
var invoice = {
invoiceItems: [
{ type: 'item',
part: '99Designs', description: '99 Designs Logo',
price: 450.00, qty: 1 },
{ type: 'service',
service: 'Web development and testing',
price: 25000.00 },
{ type: 'item',
part: 'LinodeMonthly', description: 'Monthly site hosting',
price: 40.00, qty: 12 }
]
};客户端:
<script id="invoiceTemplate" type="x-jquery-tmpl">
<table class="invoice">
{{each lineItems}}
{{tmpl($value) get_invoiceRowTemplateName(type)}}
{{/each}}
</table>
</script>Js:
$(function ()
{
$('#invoiceTemplate').tmpl(invoice).appendTo('body');
});
function get_invoiceRowTemplateName(type) {
// Return a template selector that matches our
// convention of <type>RowTemplate.
return '#' + type + 'RowTemplate';
}发布于 2010-11-16 10:46:47
别忘了行模板:
<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>当get_invoiceRowTemplateName()将每个项目的类型解析为相应的* type *RowTemplate时,这些单独的行模板将用于呈现每个项目。
https://stackoverflow.com/questions/4190412
复制相似问题