这是我的代码
<g:countrySelect name="country" value="${customerInstance?.country}"
noSelection="['':'-Choose your country-']"/>
在展会视图(页面)中 它显示的是值,而不是我希望它显示所选的选项
例如,-选择你的国家- 阿富汗 阿尔巴尼亚 在上面的示例中,我希望显示页面显示选项(“阿富汗”)而不是该值(“alg”),这是我的问题帮助我摆脱这个问题
答案 0 :(得分:1)
您必须覆盖countrySelect标记或创建自己的标记。
import org.codehaus.groovy.grails.plugins.web.taglib.CountryTagLib
class FormsTagLib {
static namespace = "bootstrap"
Closure countrySelect = { attrs ->
if (!attrs.from) {
attrs.from = CountryTagLib.COUNTRY_CODES_BY_NAME_ORDER
}
if (!attrs['valueMessagePrefix']) attrs.optionValue = { CountryTagLib.ISO3166_3[it] }
attrs.optionKey = { CountryTagLib.ISO3166_3[it] }
if (!attrs.value) {
attrs.value = attrs.remove('default')
}
out << select(attrs)
}
}
并将其命名为
<bootstrap:countrySelect name="country" value="${customerInstance?.country}" noSelection="['':'-Choose your country-']"/>
试试这个...... ,.
答案 1 :(得分:0)
您可以覆盖标记的optionKey。
例如
g:countrySelect name="country" noSelection="['':'-Choose your country-']" value="${customerInstance?.country}" optionKey="${{CountryTagLib.ISO3166_3[it]}}"
现在,optionKey和optionValue将是完整的国家/地区名称。