2011-05-21 43 views
17

我有这样的事情:的Grails G:链路通PARAMS

<g:each in="${temp}"> 

    <li>Date: ${it.dateParticipated}, <br>Role: ${it.role}, <br>Acceptence: ${it.accepted}, <br> 
    <g:link controller="conference" action="participated" id="${it.conference.id}"> 
    Conference: </g:link>${it.conference},<br> 
Role: ${it.role}, <br>Status: ${it.status}</li><br> 

    <br> 
</g:each> 

我想要做的是,当我点击“会议”时,控制器“会议”​​与方法“参加”被载入,并且params'it.conference'通过。我怎样才能在g:link标签中传递这个参数?

我需要这个,因为当我点击'会议'这个词时,其他页面会加载会议详细信息并通过ID。

回答

29

使用PARAMS属性在地图上的参数来传递:

<g:link action="/conference/participated" id="${it.conference.id}" params="[foo: 'bar', bar: 'foo']">My Link!</g:link> 

更多的例子参见the documentation

+0

我看过了。但我不明白我该如何通过'it.conference'通过它。 – robert 2011-05-21 23:17:53

+0

会议是一个完整的对象还是一个原始? – 2011-05-22 01:11:50

+2

从文档来看,这并不是非常明显,但是你可以放弃引号来引用前一个操作中设置的变量 – barrymac 2011-11-22 16:56:28

3
params="[customerId: customer.id]" 
3

您需要用$ {}包装整个参数,而不是将每个想要单独传递的变量包装起来。

<g:each in="${temp}"> 

    <li>Date: ${it.dateParticipated}, <br>Role: ${it.role}, <br>Acceptence: ${it.accepted}, <br> 
    <g:link controller="conference" action="participated" params="${[id: it.conference.id, role: it.role, status: it.status]}"> 
    Conference: </g:link> 

    <br> 
</g:each>