grails - Grails:如何在GSP表达式内调用tagLib?

标签 grails grails-2.0 gsp taglib

所以我有这个tagLib;

def trimTo = { attrs, body ->
    int length = attrs.int('length')
    String text = body()
    if (text.size() > length) {
        text = text.substring(0, length - 1) + '...'
    }
    out << text
}

通常我是这样使用的;
<g:trimTo length="50">${fieldValue(bean: fooInstance, field: "textEng")}</g:trimTo>

一切都很好。

但我想在看起来像g:select标记中调用它;
<g:select name="phrases" from="${Foo.list()}" optionValue="${{it.textEng}}" multiple="multiple" optionKey="id" size="25" value="${fooParentInstance?.children*.id}" class="many-to-many"/>

具体来说,我想用它来缩短{it.textEng}的optionValue属性所显示的内容。

我尝试了几种不同的组合,似乎无法找出正确的语法。

在此先感谢您的协助。

*针对拼写进行了编辑

最佳答案

设法弄清楚了这一点,主要是通过反复试验,并花了一点点的阅读和推理。

optionValue="${{g.trimTo([length: 50], it.textEng)}}" 

谢谢大家

关于grails - Grails:如何在GSP表达式内调用tagLib?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21708496/

相关文章:

grails - assetPath 返回不同的 URL

grails - Grails从一个域读取到另一个域

grails - 是否可以在message.properties文件中写入表达式?

hibernate - 仅在某些领域类或具有多个数据库的 Grails 项目上使用 GORM 的 Grails

Grails 标记不解析其主体中的变量

Grails - 如何从表单调用 Controller 方法

grails - Grails:在 Controller 中动态更改域的约束

jquery - 从下拉菜单更新选项

使用 @Delegate 的 Grails 3 域组合

grails - 在Grails分页问题中限制行数