首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Jquery模板plugIn

Jquery模板plugIn
EN

Stack Overflow用户
提问于 2010-11-16 09:23:32
回答 1查看 1.2K关注 0票数 2

嘿,伙计们,我正在尝试来自Dave Ward blog的这个例子

关于jQuery模板和一些我做错了的事情。任何帮助都将不胜感激。下面是他的代码: Data:

代码语言:javascript
复制
 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 }
  ]
};

客户端:

代码语言:javascript
复制
  <script id="invoiceTemplate" type="x-jquery-tmpl">
      <table class="invoice">
      {{each lineItems}}
        {{tmpl($value) get_invoiceRowTemplateName(type)}}
      {{/each}}
      </table>
  </script>

Js:

代码语言:javascript
复制
$(function ()
{
    $('#invoiceTemplate').tmpl(invoice).appendTo('body');
});

function get_invoiceRowTemplateName(type) {
  // Return a template selector that matches our 
  //  convention of <type>RowTemplate.
  return '#' + type + 'RowTemplate';
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-11-16 10:46:47

别忘了行模板:

代码语言:javascript
复制
<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时,这些单独的行模板将用于呈现每个项目。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4190412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档