HTML选择框,显示更新的值

时间:2014-06-10 07:18:55

标签: grails gsp

请帮我解决这个问题 我有这个选择框

<select name="company">
  <g:each in="${grailsApplication.config.Companies['No']}" var="no" status="index">
     <option value="${no}">${no}: ${grailsApplication.config.Companies['Name'][index]}</option>
</g:each>
</select>

选择框的值如下 option1 01:abc option2 02:def

然后,我使用表单更新,当我选择option2时,它将值保存到db,但在选择框中,默认值为01:abc,如何在更新后将其更改为02:def。

1 个答案:

答案 0 :(得分:0)

假设您要在savedValue中发送已保存的值:

<select name="company">
  <g:each in="${grailsApplication.config.company}" var="company" status="index">
    <g:if test="${grailsApplication.config.company['no'][index] == savedValue}">
        <option value="${grailsApplication.config.company['no'][index]}" selected>${grailsApplication.config.company['name'][index]}</option>
    </g:if>
    <g:else>
        <option value="${grailsApplication.config.company['no'][index]}">${grailsApplication.config.company['name'][index]}</option>
    </g:else>
  </g:each>
</select>