在 grails 中,使用 gsp 如何从域对象集合中构建逗号分隔的链接列表?
基本上我想要的是:
<g:fancyJoin in="${myList}" var="item" separator=", ">
<g:link controller="foo" action="bar" id="${item.id}">${item.label}</g:link>
</g:fancyJoin>
并且
def mylist = [[id:1, label:"first"], [id:2, label:"second"]]
它应该输出:
<a href="foo/bar/1">first</a>, <a href="foo/bar/2">second</a>
这个与现有连接标记之间的主要区别是我需要它在执行连接操作之前基本上在初始列表上进行收集和应用标记
Basically what I want is:
<g:fancyJoin in="${myList}" var="item" separator=", ">
<g:link controller="foo" action="bar" id="${item.id}">${item.label}</g:link>
</g:fancyJoin>
and for
def mylist = [[id:1, label:"first"], [id:2, label:"second"]]
it should output:
<a href="foo/bar/1">first</a>, <a href="foo/bar/2">second</a>
The key difference between this and the existing join tag is that I need it to basically do a collect and apply tags over the initial list before performing the join operation
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你不应该在普惠制中这样做。循环和条件使您的视图变得混乱,这使得维护代码变得困难,并迫使您使用非常慢的功能测试进行测试。如果您在标记库中执行此操作,则可以清理视图并且测试非常容易。
You shouldn't do this in a GSP. Cluttering your view with loops and conditionals makes it hard to maintain the code and forces you to test with functional tests which are quite slow. If you do this in a taglib you clean up the view and testing is very easy.
您可以定义一个自定义标签,例如:
用法:
You could define a custom tag, something like:
Usage: