2016-11-24 35 views
1

场景:具有传递字段的订单显示视图,总成本。传递字段不是由默认字段生成视图呈现的,所以我必须手动指定我想要查看的字段。下面的工作正常:Grails字段插件 - 作为链接的自定义收集显示成员

<f:with bean="customerOrder"> <f:display property='token' wrapper="displayText"/> <f:display property='lineItems' wrapper="displayCollection"/> <f:display property='total' wrapper="displayMoney"/> <f:display property='dateCreated' wrapper="displayDate"/> <f:display property='customer' wrapper="displayLink"/> </f:with>

的displayCollection部分由内部意见_displayWrapper.gsp文件处理/ _fields/displayCollection /它看起来像这样:

<li class="fieldcontain" style="list-style-type: none;"> <span class="property-label">${label}</span> <span class="property-value" aria-labelledby="${property}-label"> <ul> <g:each in="${value}" var="item"> <li>${item?.toString()}</li> </g:each> </ul> </span> </li>

这是一个通用收集显示字段。它将适用于购物车中的文章,用户发布的文章等。唯一的情况是,收集成员仅显示为文本,而不是链接。

如果$ {value}是单个类成员而不是集合,则下面的_displayWrapper.gsp可以正常工作。

<li class="fieldcontain" style="list-style-type: none;"> <span class="property-label">${label}</span> <span class="property-value" aria-labelledby="${property}-label"> <g:link action="show" controller="${property}" id="${value?.id}">${value?.toString()}</g:link> </span> </li>

的问题是,如何从一个集合的成员获得控制器名称,由$ {}值获得的珍藏?

我已经安装了视图模板,没有运气那里。同样,我看着插件代码字段,也没有运气。

任何想法?

回答

1

10分钟后,我已经完成了。解决方案的本质在于Grails控制器名称可以从相应的Grails域类派生。下面是相关_displayWrapper应该是什么样子:

<li class="fieldcontain" style="list-style-type: none;"> <span class="property-label">${label}</span> <span class="property-value" aria-labelledby="${property}-label"> <ul> <g:each in="${value}" var="item"> <li> <g:link controller="${item.class.getSimpleName()[0].toLowerCase() + item.class.getSimpleName().substring(1)}" action="show" id="${item.id}"> ${item?.toString()} </g:link> </li> </g:each> </ul> </span> </li>

你也可以编写自定义标签来做到这一点。