2014-07-07 43 views
0

我有一個Grails元素的Grails G:選擇optionValue

<g:select name="name" from="${list}" optionKey='code' optionValue='name' ></g:select> 

其中optionValue包含一些HTML元素像這樣,

enter image description here

我想只顯示國名,已經我嘗試使用encodeAsHTML(),但不知道如何使用。請建議。

感謝

回答

1

你不能與出的現成g.select標籤做到這一點。您需要手動循環訪問您的列表:

<select name="someName"> 
    <option value="">- no select -</option> 
    <g:each in="${list}" var="c"> 
    <option value="${c.code}">${c.name.replaceFirst(/<span class='countryName'>([\w\s]+)</span>/, '$1')}</option> 
    </g:each> 
</select> 
+0

這是不正確的,使用'raw'可以讓你通過html unncoded。根據@ user1690588 – Dave

+0

的回答,你的意思是它不起作用? – injecteer

+0

你的第一句話是不正確的。你聲明它不能使用g.select標籤完成。它可以。 – Dave

1

這是因爲XSS而發生的。而不是encodeAsHTML使用raw。試試這個:

<g:select name="name" from="${list.collect { raw(it) }}" optionKey='code' optionValue='name'/>