选择标记中的Grails noSelection属性将使用该值 [英] Grails noSelection property in the select tag over rides the value

查看:147
本文介绍了选择标记中的Grails noSelection属性将使用该值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有下面的选择标签:

            <g:select name="recommendation" from="${recommendation.list()}"
                      optionKey="id" optionValue="recommendation"
                      value="${theAssessment.recommendation}"
                      noSelection="['':'-- Select Assessor Recommendation --']"
                      />

表单的工作方式与预期的一样,当值为null时,显示noSelection。当我使用select标签选择要提交的数据时,这也可以正常工作,因为它在数据库中保留。当我回到表单时,即使值不为null,noSelection也会返回值。我查看了文档,并且完全使用此代码就像声明的那样。

The form works as expected as when the value is null the noSelection is displayed. When I use the select tag to select the data I want to submit, this also works fine as this is persisted in the database. When I then go back to the form the noSelection over rides the value even when the value is not null. I've looked at the docs and I'm using this tag exactly as stated.

推荐答案

您正在使用optionKey =id,以便将Select值指定为id。
$ b

You are using optionKey="id" so that the Select value should be assigned as id.

   // I guess your Value should be id here     
       <g:select name="recommendation" from="${recommendation.list()}" optionKey="id" optionValue="recommendation"
                  value="${theAssessment?.recommendation?.id}"
                  noSelection="['':'-- Select Assessor Recommendation --']" />

如果上面的代码不起作用,请试试这个。

If above code not work then try this.

       <g:select name="recommendation" from="${recommendation.list()}" 
              value="${theAssessment?.recommendation}"
              noSelection="['':'-- Select Assessor Recommendation --']" />

这篇关于选择标记中的Grails noSelection属性将使用该值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆