2011-12-15 113 views
2

我是grails的新手,我想将html表'cart_table'(当前位于shoppingcart.gsp)中的内容写入_carttemplate.gsp并在另一个gsp中显示此表(如摘要.gsp)通过包含这个新模板。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?并在确认页面中如何显示表格?

回答

3

这将进一步详细有关呈现模板解释: 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> 

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

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

  • 意见
      • shoppingcart.gsp
      • _carttemplate.gsp
    • 总结
      • summary.gsp

shoppingcart.gsp可以这样做:

<g:render template="carttemplate" /> 

但summary.gsp需要做:

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

这听起来很正确的,感谢您的帮助... – 2011-12-15 16:45:51