0

Here's a sample grails g:select to be rendered in a gsp:

<g:select name="user.company.id"
          from="${Company.list()}"
          value="${user?.company.id}"
          optionKey="id" />

And the HTML would look something like this:

<select id="user.company.id" name="user.company.id">
<option value="1">ABC Company</option>
<option value="2">XYZ Company</option>
</select>

So the company domain has entries for:

ABC Company
XYZ Company

I'm trying to format the text of each option, so the user would see:

Some text - ABC Company:
Some text - XYZ Company:

How can I format the output of Company.list() to include pre and post text for display in the view?

4

1 回答 1

3

使用optionValue.

<g:select name="user.company.id"
          from="${Company.list()}"
          value="${user?.company.id}"
          optionKey="id"
          optionValue="Some text - ${it.name}:" />

提供name的描述了nameCompany理想情况下,如果您已在公司中实施以默认toString()返回,则前一种情况有效)name

进一步阅读optionValue

于 2013-09-30T15:59:10.117 回答