Grails:总是以g:each获取列表的第一个元素

时间:2014-04-20 04:43:31

标签: image grails gsp

使用g:GSP页面中的迭代列表(pedaTechList):使用不同的URL来构建每个标记和构建图像。问题是我总是得到pedaTechList的第一个元素“$ {ped.id}”,同时在下面构建分配的URL。代码片段如下。请帮忙解决这个问题。

<g:each in="${pedaTechList}" var="ped" >
<div class="imgblock">
    <img style="height: 130px;"  src="${resource(dir: 'images', file: 'unfav-unchecked.png')}" alt="Criteria" usemap="#p_icons" />
    <div class="smallblackarea">
            <map name="p_icons">
            <area shape="rect" coords="0,0,18,18" href="${createLink(controller: 'pedagogy', action: 'reloadPedagogyTab', id: imod?.id, params: [objectiveId: params.objectiveId, fav:'true', assign:'false'])}" title="Favorite" alt="Favorite" />
            **<area shape="rect" coords="90,0,126,24" href="${createLink(controller: 'pedagogy', action: 'reloadPedagogyTab', id: imod?.id, params: [objectiveId: params.objectiveId, pedtecID: "${ped.id}", fav:'false', assign:'true'])}" title="Assign" alt="Assign" />**
            <area shape="rect" coords="90,90,200,200" href="http://www.google.com/" title="Clone" alt="Clone" />            
            </map>
    ${ped.pedagogyTitle}
    </div>              
</div> 
</g:each>

1 个答案:

答案 0 :(得分:0)

以下是解释: http://blog.freeside.co/post/46587122020/groovy-gotcha-for-loops-and-closure-scope

Gstrings包含在这种情况下稍后会被评估的闭包。在您的示例中,您可以替换     pedtecID:&#34; $ {ped.id}&#34; 同     pedtecID:ped.id 要么    pedtecID:&#34; $ {ped.id}&#34; as String