gpt4 book ai didi

grails - 克 :countrySelect with full country name as value

转载 作者:行者123 更新时间:2023-12-02 13:50:13 24 4
gpt4 key购买 nike

我想使用 g:countrySelect 存储确切的国家/地区名称。例如德国而不是 DEU。它是下拉菜单中的值。下拉文本是德国,但当将其保存到数据库时,它会更改回国家/地区代码。抱歉,如果我有点天真,但我已经搜索了近 3 个小时的解决方案,并且 grails 网站上没有很好的记录。我可以选择任何替代方案,甚至是ajax。只是为了有一种简单的方法来显示国家/地区列表,并且能够存储国家/地区的真实姓名而不是国家/地区代码。谢谢!

最佳答案

您可以使用此函数将 ISO3 国家/地区代码转换为国家/地区名称

def getCountryName(String countryCode) {
Locale.availableLocales.find{it.ISO3Country == countryCode}.displayCountry
}

// Test
println getCountryName('DEU') // prints 'Germany'

如果您想在 GSP 内执行此操作,最好将其作为 TagLib 提供。

关于grails - 克 :countrySelect with full country name as value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2912746/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com