我在下面有选择标签:
<g:select name="recommendation" from="${recommendation.list()}"
optionKey="id" optionValue="recommendation"
value="${theAssessment.recommendation}"
noSelection="['':'-- Select Assessor Recommendation --']"
/>
表单按预期方式工作,因为该值为null时将显示noSelection。当我使用select标记选择要提交的数据时,这也可以正常工作,因为它可以持久保存在数据库中。然后,当我返回到窗体时,即使值不为null,noSelection也将遍历该值。我已经看过docs了,并且我正按照声明使用此标记。
最佳答案
您正在使用optionKey =“id”,以便将Select值分配为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 --']" />
如果以上代码不起作用,请尝试此操作。
<g:select name="recommendation" from="${recommendation.list()}"
value="${theAssessment?.recommendation}"
noSelection="['':'-- Select Assessor Recommendation --']" />
关于grails - 使select标记中的noSelection属性超过该值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38585489/