【问题标题】:Thymeleaf: th:selected in a drop-down listThymeleaf:th:在下拉列表中选择
【发布时间】:2017-10-16 19:32:30
【问题描述】:

我想根据区域设置国家选择一个选择框的选项,但没有办法。 我试过了:

<option value="AR" th:selected="${#locale.country.contains('AR')}" >Argentina</option>
<option value="AR" th:selected="${#locale.contains('AR')}" >Argentina</option>
<option value="AR" th:selected="${__${#locale}__.contains('AR')}" >Argentina</option>
<option value="AR" th:selected="${#{__${#locale}__}.contains('AR')}" >Argentina</option>

此选项显示国家/地区(美国)

<option value="US" th:text="${#locale.country}" th:selected="${#locale.country == 'US'}"  >United States</option>

但是这个选项没有被选中。

【问题讨论】:

    标签: html spring spring-mvc spring-boot thymeleaf


    【解决方案1】:

    #locale 表达式从请求中返回 java.util.Locale 对象,因此您应该为此使用 API

    #locale.country == `AR`
    

    或者如果您更喜欢直接:

    __${#locale}__=='es_AR'
    

    默认情况下,此对象中没有contains 的方法。

    如果您需要使用th:call,这个post 也可以帮助您。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多