【问题标题】:how to check for a condition in g select tag如何检查g select标签中的条件
【发布时间】:2013-01-18 21:45:00
【问题描述】:

我是 Grails 和 GSP 的新手。
我需要使用 g:select tag

来实现以下代码
<select name="applaiances" style="width: 200px" onchange="selectedTC(this); ">
    <g:each in="${applaianceList}" var="appl">
       <g:if test="${appl == "TELEVISION"}">
          <option value="TELEVISION">TV</option>
       </g:if>
       <g:else>
          <option value="${appl}">${appl}</option>
       </g:else>
     </g:each>
</select>

任何帮助将不胜感激。

【问题讨论】:

  • Vasanth,这对你有用吗?如果有,请接受答案。
  • 谢谢 uchamp。这对我有用
  • 希望得到认可的答案。您会注意到投票向下箭头下方有一个勾号。这就是您需要单击以接受答案的内容:)

标签: grails select gsp


【解决方案1】:

尚未在应用中尝试过,但您可以尝试以下方法:

<g:select name="applaiances" onchange="selectedTC(this);" from="${applaianceList}" optionKey="${{it=='TELEVISION'?'TELEVISION':it}}" optionValue="${{it=='TELEVISION'?'TV':it}}"></g:select>

不确定 optionKey,但您可以通过 optionValue 上的闭包来应用转换。

更新: 这记录在here。只需搜索短语“如果您需要更多地控制每个人的方式”

【讨论】:

    猜你喜欢
    • 2020-04-22
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-17
    • 2014-02-11
    相关资源
    最近更新 更多