在我的 .gsp
我有一个下拉选择选项。
<g:select id="id"
name="name"
disabled="${model.x == MyEnum.X}" //<--- note here
from="${MyEnum.values()}"
optionValue="naturalName"
noSelection="['': '']"
value="${model?.x}"/>
生成的
.html
这部分看起来像这样 -<select id="id" name="name" > //n <--- note here
<option value=""></option>
<option value="A" >A</option>
</select>
*注:
disabled
属性不生成!但是 如果我首先将禁用属性的逻辑和值放在变量中-
<g:if test="${model.x == MyEnum.X}">
<g:set var="disabled" value="true"/>
</g:if>
然后,使用
disabled
中的变量属性(property) -<g:select id="id"
name="name"
disabled="${disabled}" //<------here
from="${MyEnum.values()}"
optionValue="naturalName"
noSelection="['': '']"
value="${model?.x}"/>
它按预期工作! 我的意思是,生成
disabled="disabled"
在生成 .html
文件 -<select id="id" name="name" disabled="disabled"> //n <--- here
<option value=""></option>
<option value="A" >A</option>
</select>
谁能解释这种不一致的行为为什么
.gsp
无法处理第一名 接近但第二名我说不一致是因为在这两种方法上我都做了相同的
boolean
检查但 .gsp
在第二种方法上准确地工作。仅供引用:我的 grails 版本是 2.4.4
最佳答案
我尝试了类似以下的方法,效果很好:
<div style="text-align: right;margin: 5px 10px;">
State: <g:select name="state" from="${testapp.State.values()}" value="${testapp.State.HR}" disabled="${1==1}"/>
</div>
那么,您能否分享一个复制问题的示例应用程序?
关于grails - g :select disabled property doesn't work properly,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49871828/