【问题标题】:rendering content in a gsp template在 gsp 模板中呈现内容
【发布时间】:2011-12-15 08:32:03
【问题描述】:

我是 grails 的新手,我想将 html 表 'cart_table' 的内容(当前位于 shoppingcart.gsp 中)写入 _carttemplate.gsp 并通过包含此表在另一个 gsp(如 summary.gsp)中显示此表新模板。

目前我在 shoppingcart.gsp 中定义的表如下:

<table id="newTable" style="display:none">
    <thead><th>item name</th><th>desc</th><th>business justification</th><th>start date</th><th>end date</th></thead>
    <tbody></tbody>
</table>

我按如下方式填充正文

$("#confirmbutton").click(function(){
        var ntr='',//to store html for new table row
         rows=[],//to collect new rows
        $tbl=$("#table_rolecart tbody"),//original table
        l=$("tr", $tbl).length;//length of rows in original table's tbody section
        var row, brow, drow;
        :
        : /* getting rows from other tables */
        }
        $("#newTable tbody").append(rows.join(''));

如何将表格放入template.gsp?在确认页面中如何显示表格?

【问题讨论】:

    标签: html grails groovy


    【解决方案1】:

    这将更详细地解释有关呈现模板的内容: http://grails.org/doc/latest/ref/Tags/render.html

    对于您的代码,听起来您只需在 shoppingcart.gsp 和 summary.gsp 中执行此操作:

    <g:render template="carttemplate" />
    

    那么 _carttemplate.gsp 将如下所示:

    <table id="newTable" style="display:none">
    <thead><th>item name</th><th>desc</th><th>business justification</th><th>start date</th>     <th>end date</th></thead>
        <tbody></tbody>
    </table>
    

    唯一有点棘手的部分是您如何通过 javascript 填充数据。如果您需要的多个地方可以重用相同的 javascript,那么您可以将脚本放在 .js 文件中并从呈现模板的任何 gsp 中引用它。如果它们不同,那么您将不会得到大量重复使用。

    另外请注意,您可能需要在 g:render 标签中指定模板的目录。让我们假设这个结构:

    • 查看次数
      • 购物车
        • shoppingcart.gsp
        • _carttemplate.gsp
      • 总结
        • summary.gsp

    shoppingcart.gsp 可以做到:

    <g:render template="carttemplate" />
    

    但是 summary.gsp 需要这样做:

    <g:render template="/cart/carttemplate" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-29
      • 2015-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-27
      • 1970-01-01
      相关资源
      最近更新 更多