grails g:链接帮助
嘿。想象一下我有这样的东西:
class Car{
String name
String color
String mark
}
class Motion {
String name
Car carName
}
我有我的观点(motion.gsp):
<g:each in="${motion}">
<li>Name: ${it.name}, <br>carName: ${it.carName}, </li>
<br>
</g:each>
我需要做的是,在“it.carName”字段中有一个链接,这样,当我点击它时,它会将我重定向到新页面(car.gsp)几乎与“motion.gsp”相同,但会显示汽车的属性。
所以我检查了 grails 自动生成的 gsp 文件“显示”并看到了类似这样的内容:
#<td><g:link action="show" id="${countryInstance.id}">${fieldValue(bean: countryInstance, field: "id")}</g:link></td>
#但我认为我不明白它的作用。所以我的问题是:
a)请解释一下##之间的代码是如何工作的。
b)如果可能的话,给我一个关于我需要更新到我的motion.gsp的代码的小提示
Hey. Imagine i have a something like this:
class Car{
String name
String color
String mark
}
class Motion {
String name
Car carName
}
And i have my view (motion.gsp):
<g:each in="${motion}">
<li>Name: ${it.name}, <br>carName: ${it.carName}, </li>
<br>
</g:each>
What i need to do is, have a link in the 'it.carName' field so, when i click on it, it redirects me to a new page (car.gsp) which will be almost the same as'motion.gsp' but will show the car's properties.
So i checked grails auto-generated gsp files 'show' and saw something like this:
#
<td><g:link action="show" id="${countryInstance.id}">${fieldValue(bean: countryInstance, field: "id")}</g:link></td>
#
But i dont think i understand what it does. So my questions are:
a) please explain me how the code betwen ## work.
b) if possible, give me a small hint for the code i need to update to my motion.gsp
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
g:link 只是生成一个填充的
。查看此处的文档:
基本上,在 Grails 中,您有模型、视图和控制器。 g:link 标签有助于生成根据 Grails MVC 约定有意义的链接。 g:link 的适当名称参数指定要在链接中调用的控制器以及该控制器上的哪个操作,以及要传递给该操作的参数。
尝试一下吧,并不复杂。
g:link does nothing more than generate a populated
<a href=''>
. Check out the documentation here:basically, in Grails, you have Models, Views, and Controllers. The g:link tag facilitates generating links that make sense according to the Grails MVC convention. The appropriate names parameters of g:link specify which controller, and which action on that controller, to invoke in the link, as well as parameters to pass to the action.
Just try it, its not complicated.