grails - g :select disabled property doesn't work properly

标签 grails drop-down-menu gsp disabled-input

在我的 .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/

相关文章:

java - Jersey :找不到类的语法元素

Jquery 使用值选择选项

html - 尽管位置为 : absolute?,但为什么子菜单会移动

javascript - 如何在ul下拉菜单中显示选定的菜单项

grails - 在 g :select when enum is attribute of selection object 中使用枚举值

Grails GORM 从表中返回随机行?

spring - 没有这样的属性 : springSecurityService for class: DUMMY

grails - IntelliJ Idea 10 正在拾取旧的编译类。我无法清洁它们

grails - GRAILS:.gsp文件如何解析?

grails - Grails数据库操作和 View 呈现