grails g:选择标签 [英] grails g:select tag
问题描述
< td>< g:select name =newCity
id =$ {'newCity_'+ cityData.uid}
from =$ {cityData.name}
value =$ {cityData.someValue}
noSelection =$ {['null':'选择城市...']}class =newCity/>
< / td>
呈现以下HTML:
< TD>
< select name =newCityid =newCity_abcclass =newCity>
< option value =null>选择城市...< / option>
< option value =A> A< / option>
< option value =B> B< / option>
< option value =C> C-< / option>
< option value =D> D< / option>
< / select>
< / td>
但是,我希望我的HTML看起来像这样;插入类,因为我正在做一些JavaScript验证:
< td>
< select name =newCityid =newCity_abcclass =newCity>
< option value =null>选择城市...< / option>
< option value =Aclass =populated> A< / option>
< option value =Bclass =notpopulated> B< / option>
< option value =Cclass =populated> C< / option>
< option value =Dclass =notpopulated> D< / option>
< / select>
< / td>
这可能吗?
需要创建一个自定义标签库来实现这个目标?
任何帮助将不胜感激,谢谢!
相信这是可能的。 选择标签实施(写出< option>
tags )调用私有方法 writeValueAndCheckIfSelected
来填写选项
,并且不知道任何类名。
有一个2岁的 Grails JIRA上的新功能请求,但我认为你可能被卡住了自己的标签来为你的sp做这个特别的情况。
I am using a g:select tag like this:
<td><g:select name="newCity"
id="${'newCity_' +cityData.uid}"
from="${cityData.name}"
value="${cityData.someValue}"
noSelection="${['null':'Select City...']}" class="newCity" />
</td>
which renders the following HTML:
<td>
<select name="newCity" id="newCity_abc" class="newCity" >
<option value="null">Select City...</option>
<option value="A" >A</option>
<option value="B" >B</option>
<option value="C" >C-</option>
<option value="D" >D</option>
</select>
</td>
However, I want my HTML to look like this; with class inserted since I am doing some javascript validation:
<td>
<select name="newCity" id="newCity_abc" class="newCity" >
<option value="null">Select City...</option>
<option value="A" class="populated" >A</option>
<option value="B" class="notpopulated" >B</option>
<option value="C" class="populated" >C</option>
<option value="D" class="notpopulated" >D</option>
</select>
</td>
Is this possible?
Do I need to create a custom tag library to acheive this?
Any help will be appreciated, Thanks!
I don't believe this is possible. The select tag implementation (which writes out the <option>
tags) calls the private method writeValueAndCheckIfSelected
to fill in the option
, and this is not aware of any class names.
There is a 2 year old New Feature Request on the Grails JIRA, but I think you may be stuck rolling your own tag to do this for your specific situation.
这篇关于grails g:选择标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!